From 3a5382a0117dbe7d49fda0cd7ef7c780b51de9ba Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 20 Jan 2014 07:11:57 +0100 Subject: parity via multiplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/algorithms/bits/Bits.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/algorithms/bits/Bits.java b/src/algorithms/bits/Bits.java index 3101217..ace5fed 100644 --- a/src/algorithms/bits/Bits.java +++ b/src/algorithms/bits/Bits.java @@ -343,6 +343,20 @@ public class Bits value ^= value >> 4; return (0x6996 >> (value & 15)) & 1; } + + /** + * Compute the parity of all bits in an integer, multiplication version + * + * @param value The interger + * @return The parity + */ + public static £{T} parity_multiplication(£{T} value) + { + value ^= value >> 1; + value ^= value >> 2; + value = (£{T})((value & (£{T})0x1111111111111111L) * (£{T})0x1111111111111111L); + return (£{T})((value >> (£{S} - 4)) & 1); + } £>done } -- cgit v1.2.3-70-g09d2