public 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.
|
boolean |
isMSBAccess()
Tests if this BitVector has
the MSB (leftmost) as the first bit
(i.e.
|
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 static BitVector createBitVector(byte[] data, int size)
data - a byte[] containing packed bits.size - Size to set the bit vector topublic static BitVector createBitVector(byte[] data)
data - a byte[] containing packed bits.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 void setBytes(byte[] data)
data - a byte[].public void setBytes(byte[] data,
int size)
data - a byte[].size - Size to set the bit vector topublic boolean getBit(int index)
throws IndexOutOfBoundsException
index - the index of the bit to be returned.IndexOutOfBoundsException - if the index is out of bounds.public 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 int size()
public void forceSize(int size)
size - Size to set the bit vector toIllegalArgumentException - if the size exceeds
the byte[] store size multiplied by 8.public 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.
Copyright © 2025. All Rights Reserved.