aboutsummaryrefslogtreecommitdiffstats
path: root/src/algorithms/bits/Bits.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/algorithms/bits/Bits.java')
-rw-r--r--src/algorithms/bits/Bits.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/algorithms/bits/Bits.java b/src/algorithms/bits/Bits.java
index 8f794e3..87939f7 100644
--- a/src/algorithms/bits/Bits.java
+++ b/src/algorithms/bits/Bits.java
@@ -240,6 +240,23 @@ public class Bits
value = (£{T})((value * £{L4}) >> ((£{S} - 1) * 8));
return value; /* Only applicable upto 128 bits */
}
+
+ /**
+ * Compute the parity of all bits in an integer
+ *
+ * @param value The interger
+ * @return The parity
+ */
+ public static £{T} parity_naïve(£{T} value)
+ {
+ £{T} rc = 0;
+ while (value != 0)
+ {
+ rc ^= 1;
+ value &= value - 1;
+ }
+ return rc;
+ }
£>done
}