예제 #1
0
 /**
  * Returns the int value for the last numBits of the byte array passed. Size of numBits is
  * restricted to Integer.SIZE
  *
  * @param byte[] data
  * @param int - numBits
  * @return int - the integer value of byte array
  */
 public static int getInt(byte[] data, int numBits) {
   if (numBits > Integer.SIZE) {
     try {
       throw new BufferException("Container is too small for the number of requested bits");
     } catch (BufferException e) {
       logger.error("", e);
     }
   }
   int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
   byte[] bits = null;
   try {
     bits = BitBufferHelper.getBits(data, startOffset, numBits);
   } catch (BufferException e) {
     logger.error("", e);
   }
   return (int) toNumber(bits, numBits);
 }
예제 #2
0
 /**
  * Returns the long value for the last numBits of the byte array passed. Size of numBits is
  * restricted to Long.SIZE
  *
  * @param byte[] data
  * @param int - numBits
  * @return long - the integer value of byte array
  */
 public static long getLong(byte[] data, int numBits) {
   if (numBits > Long.SIZE) {
     try {
       throw new BufferException("Container is too small for the number of requested bits");
     } catch (BufferException e) {
       logger.error("", e);
     }
   }
   if (numBits > data.length * NetUtils.NumBitsInAByte) {
     try {
       throw new BufferException("Trying to read more bits than contained in the data buffer");
     } catch (BufferException e) {
       logger.error("", e);
     }
   }
   int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
   byte[] bits = null;
   try {
     bits = BitBufferHelper.getBits(data, startOffset, numBits);
   } catch (BufferException e) {
     logger.error("", e);
   }
   return (long) toNumber(bits, numBits);
 }