aboutsummaryrefslogtreecommitdiffstats
path: root/src/algorithms/bits
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/algorithms/bits/Bits.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/algorithms/bits/Bits.java b/src/algorithms/bits/Bits.java
index 327a39e..4a08d05 100644
--- a/src/algorithms/bits/Bits.java
+++ b/src/algorithms/bits/Bits.java
@@ -48,6 +48,19 @@ public class Bits
{
return (£{T})((value & ~mask) | (-flag & mask));
}
+
+ /**
+ * Merge bits from two values
+ *
+ * @param zero Integer whose bits should be kept where the mask has zeroes
+ * @param one Integer whose bits should be kept where the mask has onces
+ * @param mask The merge mask
+ * @return {@code (zero & ~mask) | (one & mask)}
+ */
+ public static £{T} merge(£{T} zero, £{T} one, £{T} mask)
+ {
+ return (£{T})(zero ^ ((£{T})(zero ^ one) & mask));
+ }
£>done
}