Package dev.roanh.cpqindex
Class BitWriter
java.lang.Object
dev.roanh.cpqindex.BitWriter
Utility class for writing a sequence of integers to an array
while using a variable number of bits for each integer.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionBitWriter
(int bits) Constructs a new BitWriter with enough space for at least the requested number of bits. -
Method Summary
-
Field Details
-
data
private byte[] dataThe data array being written to. -
pos
private int posThe current byte in the data array being written. -
sub
private int subThe next bit in the data array to write to.
-
-
Constructor Details
-
BitWriter
public BitWriter(int bits) Constructs a new BitWriter with enough space for at least the requested number of bits.- Parameters:
bits
- The minimum number of bits to allocate space for in the data array.
-
-
Method Details
-
writeInt
public void writeInt(int i, int bits) Writes the bits of the given integer using exactly the given number of bits.- Parameters:
i
- The integer to write.bits
- The number of bit to use to write the given integer.
-
getData
public byte[] getData()Gets the array containing the written bits.- Returns:
- The data array being written to.
-
toBinaryString
Constructs a string version of the bits written.- Returns:
- A string with the written bits.
-