public class Bits extends Object
Modifier and Type | Field and Description |
---|---|
byte[] |
bits
Bits are stored in a byte array, lsb to msb
|
int |
length
The actual number of bits in this packet
|
Constructor and Description |
---|
Bits(byte[] b,
int l)
Create new Bits object from existing bytes and length (number of bits)
|
Bits(int c,
int l)
Create new Bits object of constant value (0/1) and specified length
|
Bits(String s)
Create new Bits object from String (bits are read right to left, lsb to msb)
|
Modifier and Type | Method and Description |
---|---|
Bits |
append(Bits b)
Append bit packets
|
static Bits |
asBits(byte[] b,
int l)
Helper to create a Bits object from existing byte array containing bits
|
static Bits |
asBits(int c,
int l)
Helper to create a constant-valued Bits object
|
static String |
asString(byte[] b,
int l)
Helper to create a String object from existing byte array containing bits
|
static String |
asString(int c,
int l)
Helper to create a String object with constant value bits
|
Bits |
extract(int e,
int b)
Get sub-Bits
|
int |
getBit(int p)
Get bit value
|
int |
getBits(int r)
Get value of a range of contiguous bits (high/low position encoded)
|
int |
getBits(int e,
int b)
Get value of a range of contiguous bits as an int
|
static void |
main(String[] args)
Test class
|
void |
reverse()
Reverse bits
|
static Bits |
reverse(Bits b)
Reverse bits in a packet
|
static String |
reverse(String s)
Reverse a string
|
void |
setBit(int p,
int v)
Set bit to value
|
void |
setBits(int r,
int v)
Set value of a range of contiguous bits (high/low encoded in a single int)
|
void |
setBits(int e,
int b,
int v)
Set a range of contiguous bits (up to 32) to a value.
|
String |
toString() |
public byte[] bits
public int length
public Bits(byte[] b, int l)
public Bits(int c, int l)
public Bits(String s)
public static Bits asBits(byte[] b, int l)
public static Bits asBits(int c, int l)
public static String asString(byte[] b, int l)
public static String asString(int c, int l)
public Bits extract(int e, int b)
public int getBit(int p)
public int getBits(int r)
public int getBits(int e, int b)
public static void main(String[] args)
public void reverse()
public void setBit(int p, int v)
public void setBits(int r, int v)
public void setBits(int e, int b, int v)