|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.wimpi.modbus.util.BitVector
public final class BitVector
Class that implements a collection for bits, storing them packed into bytes. Per default the access operations will index from the LSB (rightmost) bit.
Constructor Summary | |
---|---|
BitVector(int size)
Constructs a new BitVector instance with a given size. |
Method Summary | |
---|---|
int |
byteSize()
Returns the number of bytes used to store the collection of bits as int. |
static BitVector |
createBitVector(byte[] data)
Factory method for creating a BitVector instance wrapping the given byte data. |
static BitVector |
createBitVector(byte[] data,
int size)
Factory method for creating a BitVector instance wrapping the given byte data. |
void |
forceSize(int size)
Forces the number of bits in this BitVector. |
boolean |
getBit(int index)
Returns the state of the bit at the given index of this BitVector. |
byte[] |
getBytes()
Returns the byte[] which is used to store the bits of this BitVector. |
boolean |
isLSBAccess()
Tests if this BitVector has the LSB (rightmost) as the first bit (i.e. |
boolean |
isMSBAccess()
Tests if this BitVector has the MSB (leftmost) as the first bit (i.e. |
static void |
main(String[] args)
|
void |
setBit(int index,
boolean b)
Sets the state of the bit at the given index of this BitVector. |
void |
setBytes(byte[] data)
Sets the byte[] which stores the bits of this BitVector. |
void |
setBytes(byte[] data,
int size)
Sets the byte[] which stores the bits of this BitVector. |
int |
size()
Returns the number of bits in this BitVector as int. |
void |
toggleAccess(boolean b)
Toggles the flag deciding whether the LSB or the MSB of the byte corresponds to the first bit (index=0). |
String |
toString()
Returns a String representing the contents of the bit collection in a way that can be printed to a screen or log. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BitVector(int size)
size
- the number of bits the BitVector
should be able to hold.Method Detail |
---|
public void toggleAccess(boolean b)
b
- true if LSB=0 up to MSB=7, false otherwise.public boolean isLSBAccess()
public boolean isMSBAccess()
public final byte[] getBytes()
public final void setBytes(byte[] data)
data
- a byte[].public final void setBytes(byte[] data, int size)
data
- a byte[].public final boolean getBit(int index) throws IndexOutOfBoundsException
index
- the index of the bit to be returned.
IndexOutOfBoundsException
- if the index is out of bounds.public final void setBit(int index, boolean b) throws IndexOutOfBoundsException
index
- the index of the bit to be set.b
- true if the bit should be set, false if it should be reset.
IndexOutOfBoundsException
- if the index is out of bounds.public final int size()
public final void forceSize(int size)
size
-
IllegalArgumentException
- if the size exceeds
the byte[] store size multiplied by 8.public final int byteSize()
public String toString()
Note that this representation will ALLWAYS show the MSB to the left and the LSB to the right in each byte.
toString
in class Object
public static BitVector createBitVector(byte[] data, int size)
data
- a byte[] containing packed bits.
public static BitVector createBitVector(byte[] data)
data
- a byte[] containing packed bits.
public static void main(String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |