public class BitString extends Object
Modifier and Type | Field and Description |
---|---|
static BitString |
EMPTY_STRING
A null MutableString
|
Constructor and Description |
---|
BitString(byte[] bytes)
Creates a BitString from a byte[].
|
BitString(int length)
Creates a BitString with a specific length (length is the number of
bits).
|
Modifier and Type | Method and Description |
---|---|
void |
clearBit(int pos)
Clear a bit at a specified position.
|
boolean |
getBit(int pos)
Get the bit stored into the BitString at a specific position.
|
byte[] |
getData()
Get the representation of a BitString.
|
byte |
getUnusedBits()
Get the number of unused bits
|
void |
setBit(int pos)
Set a bit at a specified position.
|
void |
setData(byte[] data)
Set a new BitString in the BitString.
|
int |
size() |
String |
toString()
Return a native String representation of the BitString.
|
public static final BitString EMPTY_STRING
public BitString(int length)
length
- The BitString length (it's a number of bits)public BitString(byte[] bytes)
bytes
- The value to store. The first byte contains the number of
unused bitspublic void setData(byte[] data)
data
- The string to storepublic byte[] getData()
public byte getUnusedBits()
public void setBit(int pos)
pos
- The bit to setpublic void clearBit(int pos)
pos
- The bit to clearpublic boolean getBit(int pos)
With '1001 000x', where x is an unused bit, ^ ^ ^ | | | | | | | | +----- getBit(6) = 0 | +---------- getBit(2) = 0 +------------ getBit(0) = 1
pos
- The position of the requested bit.true
if the bit is set, false
otherwisepublic int size()
Copyright © 2003–2023 The Apache Software Foundation. All rights reserved.