public abstract class BitVector extends java.lang.Object implements java.lang.Comparable<BitVector>
Modifier and Type | Field and Description |
---|---|
static int |
BITS_IN_BYTE
Number of bits an a byte.
|
static BitVector |
FALSE
A constant bit vector that represents the 'false' boolean value (bit size is 1).
|
static BitVector |
TRUE
A constant bit vector that represents the 'true' boolean value (bit size is 1).
|
Constructor and Description |
---|
BitVector() |
Modifier and Type | Method and Description |
---|---|
void |
assign(BitVector src)
Copies data from the specified bit vector to the current bit vector.
|
java.math.BigInteger |
bigIntegerValue()
Converts the stored data to a BigInteger value.
|
java.math.BigInteger |
bigIntegerValue(boolean signed)
Converts the stored data to a BigInteger value.
|
int |
compareTo(BitVector other)
Compares the current bit vector with the specified bit vector.
|
BitVector |
copy()
Creates a copy of current bit vector.
|
static BitVector |
copyOf(BitVector src)
Creates a copy of the specified bit vector.
|
boolean |
equals(java.lang.Object obj)
Checks the equality of bit vectors.
|
BitVector |
field(BitVector startBitPos,
BitVector endBitPos)
Returns a field of the bit vector limited by the specified bounds.
|
BitVector |
field(int startBitPos,
int endBitPos)
Returns a field of the bit vector limited by the specified bounds.
|
boolean |
getBit(int index)
Returns a boolean flag that corresponds to the value of the specified bit.
|
abstract int |
getBitSize()
Returns the size of stored data in bits.
|
abstract byte |
getByte(int index)
Returns the binary value stored in the specified byte.
|
byte |
getByteBitMask(int index)
Returns the mask for the specified byte in the byte array.
|
abstract int |
getByteSize()
Returns the size of stored data in bytes (full number including incomplete bytes).
|
int |
hashCode()
Returns the hash code value for this bit vector.
|
int |
intValue()
Converts the stored data to an integer value.
|
boolean |
isAllReset()
Checks whether all bits in the bit vector are reset (equal to 0).
|
boolean |
isAllSet()
Checks whether all bits in the bit vector are set (equal to 1).
|
long |
longValue()
Converts the stored data to an long value.
|
static BitVector |
newEmpty(int bitSize)
Creates an uninitialized bit vector of the specified size.
|
static BitVector |
newMapping(BitVector... sources)
Creates a mapping for several bit vectors.
|
static BitVector |
newMapping(BitVector source,
int startBitPos,
int bitSize)
Creates a bit vector mapping for the current bit vector.
|
void |
reset()
Resets (set to zero) all bits in the bit vector.
|
BitVector |
resize(int newBitSize,
boolean signExt)
Returns a resized copy of the current bit vector.
|
void |
setAll()
Sets (sets to one) all bits in the bit vector.
|
void |
setBit(int index,
boolean value)
Sets or resets the specified bit.
|
abstract void |
setByte(int index,
byte value)
Sets the value of the specified byte in the data array.
|
java.lang.String |
toBinString()
Converts the stored binary data to textual representation.
|
byte[] |
toByteArray()
Returns a copy of stored data packed into an array of bytes.
|
java.lang.String |
toHexString()
Converts the stored binary data to a hexadecimal string.
|
java.lang.String |
toString()
Converts the stored data to a string (binary format).
|
static BitVector |
unmodifiable(BitVector source)
Returns an unmodifiable view of the specified bit vector.
|
static BitVector |
valueOf(java.math.BigInteger value,
int bitSize)
Creates a bit vector based on a BigInteger value.
|
static BitVector |
valueOf(boolean b)
Returns a bit vector that corresponds to the specified boolean value.
|
static BitVector |
valueOf(byte[] data,
int bitSize)
Creates a bit vector from a byte array.
|
static BitVector |
valueOf(int value,
int bitSize)
Creates a bit vector based on a integer value.
|
static BitVector |
valueOf(long value,
int bitSize)
Creates a bit vector based on a long value.
|
static BitVector |
valueOf(java.lang.String bs)
Creates a bit vector based on textual representation of binary data.
|
static BitVector |
valueOf(java.lang.String text,
int radix,
int bitSize)
Creates a bit vector based on textual representation of binary data.
|
public static final BitVector FALSE
public static final BitVector TRUE
public static final int BITS_IN_BYTE
public abstract int getBitSize()
public abstract int getByteSize()
public abstract byte getByte(int index)
index
- Index of the target byte.public abstract void setByte(int index, byte value)
index
- Index of the target byte.value
- Binary value to be stored in the specified byte.public final boolean getBit(int index)
index
- Bit index.true
if the bit is set to 1
or false
otherwise.java.lang.IndexOutOfBoundsException
- if the index is out of range.public final void setBit(int index, boolean value)
index
- Bit index.value
- true
to set the bit to 1
or false
to set it to 0
.java.lang.IndexOutOfBoundsException
- if the index is out of range.public final void setAll()
public final void reset()
public final boolean isAllSet()
true
if all bits are set or false
otherwise.public final boolean isAllReset()
true
if all bits are reset or false
otherwise.public final void assign(BitVector src)
src
- Source it vector.public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- A bit vector to be compared with the current bit vector.public final int hashCode()
hashCode
in class java.lang.Object
public final int compareTo(BitVector other)
compareTo
in interface java.lang.Comparable<BitVector>
other
- A raw data object.java.lang.IllegalArgumentException
- if the other
parameter is null
;
if the size of the other
bit vector is different from the size of
the current bit vector.public final BitVector copy()
public final BitVector field(BitVector startBitPos, BitVector endBitPos)
startBitPos
- Bit vector that holds start position in bits.endBitPos
- Bit vector that holds end position in bits.public final BitVector field(int startBitPos, int endBitPos)
startBitPos
- Start position in bits.endBitPos
- End position in bits.public BitVector resize(int newBitSize, boolean signExt)
newBitSize
- New size in bits.signExt
- Flag that specifies whether sign extension is required.java.lang.IllegalArgumentException
- if the new size is <= 0
.public static BitVector copyOf(BitVector src)
src
- Source bit vector.public static BitVector newEmpty(int bitSize)
bitSize
- Size of the created bit vector in bits.public static BitVector newMapping(BitVector source, int startBitPos, int bitSize)
source
- Source bit vector.startBitPos
- The starting position of the mapping.bitSize
- The size of the mapping in bytes.public static BitVector newMapping(BitVector... sources)
sources
- Source bit vectors.public static BitVector unmodifiable(BitVector source)
source
- Source bit vector.public static BitVector valueOf(java.lang.String bs)
bs
- Textual representation of binary data.public static BitVector valueOf(boolean b)
b
- Boolean value.public final java.lang.String toString()
toString
in class java.lang.Object
public static BitVector valueOf(java.lang.String text, int radix, int bitSize)
text
- Textual representation of binary data.radix
- Radix to be used during conversion.bitSize
- Size of the resulting bit vector in bits.java.lang.IllegalArgumentException
- if the text
parameter is null
;
if the bitSize
parameter is zero or negative.public static BitVector valueOf(long value, int bitSize)
value
- Long value to be converted to a bit vector.bitSize
- Size of the resulting data array (in bits).java.lang.IllegalArgumentException
- if the bitSize
parameter is zero or negative.public static BitVector valueOf(byte[] data, int bitSize)
data
- An array of bytes.bitSize
- Size of the resulting bit vector in bits.java.lang.IllegalArgumentException
- if the data
parameter is null
;
if the bitSize
parameter is zero or negative.public static BitVector valueOf(int value, int bitSize)
value
- Integer value to be converted to a bit array.bitSize
- Size of the resulting data array (in bits).java.lang.IllegalArgumentException
- if the bitSize
parameter is zero or negative.public static BitVector valueOf(java.math.BigInteger value, int bitSize)
toByteArray
method), the data is truncated (high bits are ignored).
If the bit vector size exceeds the data size, the data is sign extended (high bits are
filled with zeros for a non-negative value or with ones for a negative value).value
- BigInteger value to be converted to a bit vector.bitSize
- Size of the resulting bit vector (in bits).java.lang.IllegalArgumentException
- if the value
parameter is null
;
if the bitSize
parameter is zero or negative.public final int intValue()
public final long longValue()
public final java.math.BigInteger bigIntegerValue()
public final java.math.BigInteger bigIntegerValue(boolean signed)
signed
- boolean value indicating should the bit vector be treated as signed integer.public final java.lang.String toBinString()
public final java.lang.String toHexString()
public final byte[] toByteArray()
public final byte getByteBitMask(int index)
index
- Index of the target byte.