public class BitField extends Object
Constructor and Description |
---|
BitField(byte[] bitfield,
int size)
Creates a new BitField that represents
size bits
as set by the given byte array. |
BitField(int size)
Creates a new BitField that represents
size unset bits. |
Modifier and Type | Method and Description |
---|---|
void |
clear(int bit)
Sets the given bit to false.
|
boolean |
complete()
Return true if all bits are set.
|
int |
count()
Return the number of set bits.
|
boolean |
get(int bit)
Return true if the bit is set or false if it is not.
|
byte[] |
getFieldBytes()
This returns the actual byte array used.
|
void |
set(int bit)
Sets the given bit to true.
|
void |
setAll()
Sets all bits to true.
|
int |
size()
Return the size of the BitField.
|
String |
toString() |
public BitField(int size)
size
unset bits.public BitField(byte[] bitfield, int size)
size
bits
as set by the given byte array. This will make a copy of the array.
Extra bytes will be ignored.IndexOutOfBoundsException
- if give byte array is not large
enough.public byte[] getFieldBytes()
public int size()
public void set(int bit)
IndexOutOfBoundsException
- if bit is smaller then zero
bigger then size (inclusive).public void clear(int bit)
IndexOutOfBoundsException
- if bit is smaller then zero
bigger then size (inclusive).public void setAll()
public boolean get(int bit)
IndexOutOfBoundsException
- if bit is smaller then zero
bigger then size (inclusive).public int count()
public boolean complete()