aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-01-20 03:23:37 +0100
committerMattias Andrée <maandree@operamail.com>2014-01-20 03:23:37 +0100
commita966aa2eb460d768245fa6f0a8bea06319b5ecb3 (patch)
tree8f78e43c8f025bda8fec0e0fdc11597ee630519c /src
parentadd set_clear (diff)
downloadalgorithms-and-data-structures-a966aa2eb460d768245fa6f0a8bea06319b5ecb3.tar.gz
algorithms-and-data-structures-a966aa2eb460d768245fa6f0a8bea06319b5ecb3.tar.bz2
algorithms-and-data-structures-a966aa2eb460d768245fa6f0a8bea06319b5ecb3.tar.xz
add bit merge
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-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
}