| Constructor and Description |
|---|
BitArray()Creates a new empty BitArray with zero size. |
BitArray(int size)Creates a new BitArray with the specified size. |
BitArray(int[] bits,
int size)For testing only. |
| Modifier and Type | Method and Description |
|---|---|
void | appendBit(boolean bit)Appends a single bit to the end of the array. |
void | appendBitArray(BitArray other)Appends another BitArray to the end of this array. |
void | appendBits(int value,
int numBits)Appends the least-significant bits, from value, in order from most-significant to
least-significant. |
void | clear()Clears all bits (sets to false). |
BitArray | clone() |
boolean | equals(Object o) |
void | flip(int i)Flips bit i. |
boolean | get(int i)Gets the bit at the specified index. |
int[] | getBitArray()Returns the underlying array of ints. |
int | getNextSet(int from)Gets the index of the next set bit. |
int | getNextUnset(int from)Gets the index of the next unset bit. |
int | getSize()Get the number of bits in the array. |
int | getSizeInBytes()Get the size of the array in bytes. |
int | hashCode() |
boolean | isRange(int start,
int end,
boolean value)Efficient method to check if a range of bits is set, or not set. |
void | reverse()Reverses all bits in the array. |
void | set(int i)Sets bit i. |
void | setBulk(int i,
int newBits)Sets a block of 32 bits, starting at bit i. |
void | setRange(int start,
int end)Sets a range of bits. |
void | toBytes(int bitOffset,
byte[] array,
int offset,
int numBytes)Writes the bits to an array of bytes. |
String | toString() |
void | xor(BitArray other)Performs a bitwise XOR of this array with another. |
public BitArray()
public BitArray(int size)
size - the number of bits in the arrayBitArray(int[] bits,
int size)bits - the bit array datasize - the number of bitspublic void appendBit(boolean bit)
bit - the bitpublic void appendBitArray(BitArray other)
other - the BitArray to appendpublic void appendBits(int value,
int numBits)value - int containing bits to appendnumBits - bits from value to appendpublic void clear()
public boolean equals(Object o)
public void flip(int i)
i - bit to setpublic boolean get(int i)
i - bit to getpublic int[] getBitArray()
public int getNextSet(int from)
from - first bit to checkgetNextUnset(int)public int getNextUnset(int from)
from - index to start looking for unset bitsize if none are unset until the endgetNextSet(int)public int getSize()
public int getSizeInBytes()
public int hashCode()
public boolean isRange(int start,
int end,
boolean value)start - start of range, inclusive.end - end of range, exclusivevalue - if true, checks that bits in range are set, otherwise checks that they are not setIllegalArgumentException - if end is less than start or the range is not contained in the arraypublic void reverse()
public void set(int i)
i - bit to setpublic void setBulk(int i,
int newBits)i - first bit to setnewBits - the new value of the next 32 bits. Note again that the least-significant bit
corresponds to bit i, the next-least-significant to i+1, and so on.public void setRange(int start,
int end)start - start of range, inclusive.end - end of range, exclusivepublic void toBytes(int bitOffset,
byte[] array,
int offset,
int numBytes)bitOffset - first bit to start writingarray - array to write into. Bytes are written most-significant byte first. This is the opposite
of the internal representation, which is exposed by getBitArray()offset - position in array to start writingnumBytes - how many bytes to writepublic String toString()
public void xor(BitArray other)
other - the BitArray to XOR withIllegalArgumentException - if sizes don't match