public final class BitVector extends Object
| Constructor and Description |
|---|
BitVector(int size)
Constructs a new BitVector instance
with a given size.
|
| Modifier and Type | Method and Description |
|---|---|
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. at index 0).
|
boolean |
isMSBAccess()
Tests if this BitVector has
the MSB (leftmost) as the first bit
(i.e. at index 0).
|
static void |
main(String[] args)
The entry point of application.
|
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.
|
public BitVector(int size)
size - the number of bits the BitVector should be able to hold.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[].size - the sizepublic 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 - the sizeIllegalArgumentException - 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.
public static BitVector createBitVector(byte[] data, int size)
data - a byte[] containing packed bits.size - the sizepublic static BitVector createBitVector(byte[] data)
data - a byte[] containing packed bits.public static void main(String[] args)
args - the input argumentsCopyright © 2017. All rights reserved.