From f6d75da8dae8767644987a2434b038f359dc8652 Mon Sep 17 00:00:00 2001 From: Krapht Date: Wed, 17 Apr 2013 18:46:03 +0200 Subject: [PATCH] Added BitSet codec --- .../transport/utils/BitSetCodec.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 common/buildcraft/transport/utils/BitSetCodec.java diff --git a/common/buildcraft/transport/utils/BitSetCodec.java b/common/buildcraft/transport/utils/BitSetCodec.java new file mode 100644 index 00000000..7aa4fdf8 --- /dev/null +++ b/common/buildcraft/transport/utils/BitSetCodec.java @@ -0,0 +1,22 @@ +package buildcraft.transport.utils; + +import java.util.BitSet; + +public class BitSetCodec { + public byte encode(BitSet set){ + byte result = 0; + for (byte i = 0; i < set.length() && i < 8; i++ ){ + if (set.get(i)){ + result |= 0x1 << i; + } + } + return result; + } + + public void decode(byte data, BitSet target){ + target.clear(); + for (byte i = 0; i < target.length() && i < 8; i++){ + target.set(i, (data & 0x1 >>> i) > 0); + } + } +}