Added BitSet codec
This commit is contained in:
parent
83dfaf02d3
commit
f6d75da8da
1 changed files with 22 additions and 0 deletions
22
common/buildcraft/transport/utils/BitSetCodec.java
Normal file
22
common/buildcraft/transport/utils/BitSetCodec.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue