From a966aa2eb460d768245fa6f0a8bea06319b5ecb3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 20 Jan 2014 03:23:37 +0100 Subject: add bit merge 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') 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 } -- cgit v1.2.3-70-g09d2