Added BitSet codec

This commit is contained in:
Krapht 2013-04-17 18:46:03 +02:00
parent 83dfaf02d3
commit f6d75da8da

View file

@ -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);
}
}
}