/**
* Returns the short value for the byte array passed.
* Size of byte array is restricted to Short.SIZE
/**
* Returns the short value for the byte array passed.
* Size of byte array is restricted to Short.SIZE
/**
* Returns the int value for the byte array passed.
* Size of byte array is restricted to Integer.SIZE
/**
* Returns the int value for the byte array passed.
* Size of byte array is restricted to Integer.SIZE
}
/**
* Returns the short value for the last numBits of the byte array passed.
* Size of numBits is restricted to Short.SIZE
}
/**
* Returns the short value for the last numBits of the byte array passed.
* Size of numBits is restricted to Short.SIZE
* @return short - the short value of byte array
*/
public static short getShort(byte[] data, int numBits) {
* @return short - the short value of byte array
*/
public static short getShort(byte[] data, int numBits) {
/**
* Returns the int value for the last numBits of the byte array passed.
* Size of numBits is restricted to Integer.SIZE
/**
* Returns the int value for the last numBits of the byte array passed.
* Size of numBits is restricted to Integer.SIZE
* @return int - the integer value of byte array
*/
public static int getInt(byte[] data, int numBits) {
* @return int - the integer value of byte array
*/
public static int getInt(byte[] data, int numBits) {
/**
* Returns the long value for the last numBits of the byte array passed.
* Size of numBits is restricted to Long.SIZE
/**
* Returns the long value for the last numBits of the byte array passed.
* Size of numBits is restricted to Long.SIZE
* @return long - the integer value of byte array
*/
public static long getLong(byte[] data, int numBits) {
* @return long - the integer value of byte array
*/
public static long getLong(byte[] data, int numBits) {
* 0101000010 | 0000101 | 1111001010010101011
* will be returned as {0,0,0,0,0,1,0,1}
*
* 0101000010 | 0000101 | 1111001010010101011
* will be returned as {0,0,0,0,0,1,0,1}
*
- * @param byte[] data
- * @param int startOffset - offset to start fetching bits from data from
- * @param int numBits - number of bits to be fetched from data
+ * @param startOffset - offset to start fetching bits from data from
+ * @param numBits - number of bits to be fetched from data
return bytes;
} else {
System.arraycopy(data, startByteOffset, bytes, 0, numBytes - 1);
return bytes;
} else {
System.arraycopy(data, startByteOffset, bytes, 0, numBytes - 1);
- * @param byte[] - data to set the input byte
- * @param byte - input byte to be inserted
- * @param startOffset - offset of data[] to start inserting byte from
- * @param numBits - number of bits of input to be inserted into data[]
+ * @param data to set the input byte
+ * @param input byte to be inserted
+ * @param startOffset offset of data[] to start inserting byte from
+ * @param numBits number of bits of input to be inserted into data[]
*
* @throws BufferException
* when the input, startOffset and numBits are not congruent
*
* @throws BufferException
* when the input, startOffset and numBits are not congruent
- * @param byte[] - data to set the input byte
- * @param byte[] - input bytes to be inserted
- * @param startOffset - offset of data[] to start inserting byte from
- * @param numBits - number of bits of input to be inserted into data[]
- * @return void
+ * @param data to set the input byte
+ * @param input bytes to be inserted
+ * @param startOffset offset of data[] to start inserting byte from
+ * @param numBits number of bits of input to be inserted into data[]
* @throws BufferException
* when the startOffset and numBits parameters are not congruent
* with data and input buffers' size
* @throws BufferException
* when the startOffset and numBits parameters are not congruent
* with data and input buffers' size
* @return long - numerical value of byte array passed
*/
static public long toNumber(byte[] array, int numBits) {
* @return long - numerical value of byte array passed
*/
static public long toNumber(byte[] array, int numBits) {
* 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]
* 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]
public static byte[] toByteArray(Number input) {
Class<? extends Number> dataType = input.getClass();
short size = 0;
public static byte[] toByteArray(Number input) {
Class<? extends Number> dataType = input.getClass();
short size = 0;
* It aligns the last numBits bits to the head of the byte array following
* them with numBits % 8 zero bits.
*
* Example: For inputbytes = [00000111][01110001] and numBits = 12 it
* returns: shiftedBytes = [01110111][00010000]
*
* It aligns the last numBits bits to the head of the byte array following
* them with numBits % 8 zero bits.
*
* Example: For inputbytes = [00000111][01110001] and numBits = 12 it
* returns: shiftedBytes = [01110111][00010000]
*
* Example: For inputbytes = [01110111][00010000] and numBits = 12 it
* returns: shiftedBytes = [00000111][01110001]
*
* Example: For inputbytes = [01110111][00010000] and numBits = 12 it
* returns: shiftedBytes = [00000111][01110001]
*
* Insert in the data buffer at position dictated by the offset the number
* of bits specified from the input data byte array. The input byte array
* has the bits stored starting from the LSB
* Insert in the data buffer at position dictated by the offset the number
* of bits specified from the input data byte array. The input byte array
* has the bits stored starting from the LSB
*/
public static void insertBits(byte[] data, byte[] inputdataLSB,
int startOffset, int numBits) {
*/
public static void insertBits(byte[] data, byte[] inputdataLSB,
int startOffset, int numBits) {
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte
- extraOffsetBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte
- extraOffsetBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(RestBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
: InputMSBbits + 256;
data[startByteOffset + i] = (byte) ((data[startByteOffset + i])
| (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
} else if (RestBits == (NetUtils.NumBitsInAByte - extraOffsetBits)) {
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(RestBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
: InputMSBbits + 256;
data[startByteOffset + i] = (byte) ((data[startByteOffset + i])
| (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
} else if (RestBits == (NetUtils.NumBitsInAByte - extraOffsetBits)) {
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte
- extraOffsetBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte
- extraOffsetBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
data[startByteOffset + i] = (byte) (data[startByteOffset + i]
| (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
} else {
data[startByteOffset + i] = (byte) (data[startByteOffset + i]
| (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
} else {
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte
- extraOffsetBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
InputMSBbits = (byte) (inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte
- extraOffsetBits)));
InputMSBbits = (InputMSBbits >= 0) ? InputMSBbits
* are not congruent with the data buffer's size
*/
public static void checkExceptions(byte[] data, int startOffset, int numBits)
* are not congruent with the data buffer's size
*/
public static void checkExceptions(byte[] data, int startOffset, int numBits)