Class BitString
java.lang.Object
org.apache.directory.api.asn1.util.BitString
Implement the Bit String primitive type. A BitString is internally stored as
an array of byte.
- Author:
- Apache Directory Project
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclearBit(int pos) Clear a bit at a specified position.booleangetBit(int pos) Get the bit stored into the BitString at a specific position.byte[]getData()Get the representation of a BitString.byteGet the number of unused bitsvoidsetBit(int pos) Set a bit at a specified position.voidsetData(byte[] data) Set a new BitString in the BitString.intsize()Get the number of stored bitstoString()Return a native String representation of the BitString.
-
Field Details
-
EMPTY_STRING
A null MutableString
-
-
Constructor Details
-
BitString
public BitString(int length) Creates a BitString with a specific length (length is the number of bits).- Parameters:
length- The BitString length (it's a number of bits)
-
BitString
public BitString(byte[] bytes) Creates a BitString from a byte[]. As the first byte is the number of unused bits in the last byte, we have to ignore it.- Parameters:
bytes- The value to store. The first byte contains the number of unused bits
-
-
Method Details
-
setData
public void setData(byte[] data) Set a new BitString in the BitString. It will replace the old BitString, and reset the current length with the new one.- Parameters:
data- The string to store
-
getData
public byte[] getData()Get the representation of a BitString. A first byte containing the number of unused bits is added- Returns:
- A byte array which represent the BitString
-
getUnusedBits
public byte getUnusedBits()Get the number of unused bits- Returns:
- A byte which represent the number of unused bits
-
setBit
public void setBit(int pos) Set a bit at a specified position. The bits are stored from left to right. For instance, if we have 10 bits, then they are coded as b0 b1 b2 b3 b4 b5 b6 b7 - b8 b9 x x x x x x- Parameters:
pos- The bit to set
-
clearBit
public void clearBit(int pos) Clear a bit at a specified position. The bits are stored from left to right. For instance, if we have 10 bits, then they are coded as b0 b1 b2 b3 b4 b5 b6 b7 - b8 b9 x x x x x x- Parameters:
pos- The bit to clear
-
getBit
public boolean getBit(int pos) Get the bit stored into the BitString at a specific position. The bits are stored from left to right, the LSB on the left and the MSB on the right.
For instance, if we have 10 bits, then they are coded as b0 b1 b2 b3 - b4 b5 b6 b7 - b8 b9 x x - x x x xWith '1001 000x', where x is an unused bit, ^ ^ ^ | | | | | | | | +----- getBit(6) = 0 | +---------- getBit(2) = 0 +------------ getBit(0) = 1- Parameters:
pos- The position of the requested bit.- Returns:
trueif the bit is set,falseotherwise
-
size
public int size()Get the number of stored bits- Returns:
- The number of bits stored in this BitString
-
toString
-