public abstract class BitBufferHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static long |
ByteMask |
protected static org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
BitBufferHelper() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkExceptions(byte[] data,
int startOffset,
int numBits)
Checks for overflow and underflow exceptions
|
static byte[] |
getBits(byte[] data,
int startOffset,
int numBits)
Reads the specified number of bits from the passed byte array
starting to read from the specified offset
The bits read are stored in a byte array which size is dictated
by the number of bits to be stored.
|
static byte |
getByte(byte[] data)
Returns the first byte from the byte array
|
static int |
getInt(byte[] data)
Returns the int value for the byte array passed.
|
static int |
getInt(byte[] data,
int numBits)
Returns the int value for the last numBits of the byte array passed.
|
static long |
getLong(byte[] data)
Returns the long value for the byte array passed.
|
static long |
getLong(byte[] data,
int numBits)
Returns the long value for the last numBits of the byte array passed.
|
static int |
getLSBMask(int numBits)
Returns numBits 1's in the LSB position
|
static int |
getMSBMask(int numBits)
Returns numBits 1's in the MSB position
|
static short |
getShort(byte[] data)
Returns the short value for the byte array passed.
|
static short |
getShort(byte[] data,
int numBits)
Returns the short value for the last numBits of the byte array passed.
|
static void |
insertBits(byte[] data,
byte[] inputdataLSB,
int startOffset,
int numBits)
Insert in the data buffer at position dictated by the offset the number
of bits specified from the input data byte array.
|
static void |
setByte(byte[] data,
byte input,
int startOffset,
int numBits)
Bits are expected to be stored in the input byte array from LSB
|
static void |
setBytes(byte[] data,
byte[] input,
int startOffset,
int numBits)
Bits are expected to be stored in the input byte array from LSB
|
static byte[] |
shiftBitsToLSB(byte[] inputBytes,
int numBits)
It aligns the first numBits bits to the right end of the byte array
preceding them with numBits % 8 zero bits.
|
static byte[] |
shiftBitsToMSB(byte[] inputBytes,
int numBits)
It aligns the last numBits bits to the head of the byte array following
them with numBits % 8 zero bits.
|
static byte[] |
toByteArray(Number input)
Accepts a number as input and returns its value in byte form in LSB
aligned form example: input = 5000 [1001110001000] bytes = 19, -120
[00010011] [10001000]
|
static byte[] |
toByteArray(Number input,
int numBits)
Accepts a number as input and returns its value in byte form in MSB
aligned form example: input = 5000 [1001110001000] bytes = -114, 64
[10011100] [01000000]
|
static long |
toNumber(byte[] array)
Returns the numerical value of the byte array passed
|
static long |
toNumber(byte[] array,
int numBits)
Returns the numerical value of the last numBits (LSB bits) of the byte
array passed
|
protected static final org.slf4j.Logger logger
public static final long ByteMask
public static byte getByte(byte[] data)
byte[] - datapublic static short getShort(byte[] data)
byte[] - datapublic static int getInt(byte[] data)
byte[] - datapublic static long getLong(byte[] data)
byte[] - datapublic static short getShort(byte[] data,
int numBits)
byte[] - dataint - - numBitspublic static int getInt(byte[] data,
int numBits)
byte[] - dataint - - numBitspublic static long getLong(byte[] data,
int numBits)
byte[] - dataint - - numBitspublic static byte[] getBits(byte[] data,
int startOffset,
int numBits)
throws BufferException
byte[] - dataint - startOffset - offset to start fetching bits from data fromint - numBits - number of bits to be fetched from dataBufferException - when the startOffset and numBits parameters are not congruent
with the data buffer sizepublic static void setByte(byte[] data,
byte input,
int startOffset,
int numBits)
throws BufferException
byte[] - - data to set the input bytebyte - - input byte to be insertedstartOffset - - offset of data[] to start inserting byte fromnumBits - - number of bits of input to be inserted into data[]BufferException - when the input, startOffset and numBits are not congruent
with the data buffer sizepublic static void setBytes(byte[] data,
byte[] input,
int startOffset,
int numBits)
throws BufferException
byte[] - - data to set the input bytebyte[] - - input bytes to be insertedstartOffset - - offset of data[] to start inserting byte fromnumBits - - number of bits of input to be inserted into data[]BufferException - when the startOffset and numBits parameters are not congruent
with data and input buffers' sizepublic static int getMSBMask(int numBits)
numBits - public static int getLSBMask(int numBits)
numBits - public static long toNumber(byte[] array)
byte[] - - arraypublic static long toNumber(byte[] array,
int numBits)
byte[] - - arrayint - - numBitspublic static byte[] toByteArray(Number input)
Number - public static byte[] toByteArray(Number input, int numBits)
Number - inputint - numBits - the number of bits to be returnedpublic static byte[] shiftBitsToMSB(byte[] inputBytes,
int numBits)
byte[] - inputBytesint - numBits - number of bits to be left alignedpublic static byte[] shiftBitsToLSB(byte[] inputBytes,
int numBits)
byte[] - inputBytesint - numBits - number of bits to be right alignedpublic static void insertBits(byte[] data,
byte[] inputdataLSB,
int startOffset,
int numBits)
byte[] - databyte[] - inputdataint - startOffsetint - numBitspublic static void checkExceptions(byte[] data,
int startOffset,
int numBits)
throws BufferException
data - startOffset - numBits - PacketException - when the startOffset and numBits parameters
are not congruent with the data buffer's sizeBufferExceptionCopyright © 2015. All Rights Reserved.