public long bits2UInt(int nb) throws IOException {
    assert nb <= 64;
    assert nb >= 0;

    long result = 0;
    int bitsLeft = nb;

    while (bitsLeft > 0) {

      // we ran out of bits - fetch the next byte...
      if (bitPos == 0) {
        bitBuf = nextByte();
        bitPos = BIT_LENGTH;
      }

      // -- retrieve bit from current byte ----------
      // how many bits to read from the current byte
      int size = Math.min(bitsLeft, bitPos);
      // move my part to start
      int myBits = bitBuf >> (bitPos - size);
      // mask-off sign-extending
      myBits &= BYTE_BITMASK;
      // mask-off bits of next value
      myBits &= ~(BYTE_BITMASK << size);

      // -- put bit to result ----------------------
      // where to place myBits inside of result
      int shift = bitsLeft - size;
      assert shift >= 0;

      // put it there
      result |= myBits << shift;

      // -- put bit to result ----------------------
      // update information on what we consumed
      bitsLeft -= size;
      bitPos -= size;
    }

    return result;
  }
public long bits2UInt(int nb) throws IOException {
    assert nb <= 64;
    assert nb >= 0;

    long result = 0;
    int bitsLeft = nb;

    while (bitsLeft > 0) {

      
      if (bitPos == 0) {
        bitBuf = nextByte();
        bitPos = BIT_LENGTH;
      }

      
      
      int size = Math.min(bitsLeft, bitPos);
      
      int myBits = bitBuf >> (bitPos - size);
      
      myBits &= BYTE_BITMASK;
      
      myBits &= ~(BYTE_BITMASK << size);

      
      
      int shift = bitsLeft - size;
      assert shift >= 0;

      
      result |= myBits << shift;

      
      
      bitsLeft -= size;
      bitPos -= size;
    }

    return result;
  }
public long bits2UInt ( int nb ) throws IOException { assert nb <= 64 ; assert nb >= 0 ; long result = 0 ; int bitsLeft = nb ; while ( bitsLeft > 0 ) { // we ran out of bits - fetch the next byte...
 if ( bitPos == 0 ) { bitBuf = nextByte ( ) ; bitPos = BIT_LENGTH ; } // -- retrieve bit from current byte ----------
 // how many bits to read from the current byte
 int size = Math . min ( bitsLeft , bitPos ) ; // move my part to start
 int myBits = bitBuf >> ( bitPos - size ) ; // mask-off sign-extending
 myBits &= BYTE_BITMASK ; // mask-off bits of next value
 myBits &= ~ ( BYTE_BITMASK << size ) ; // -- put bit to result ----------------------
 // where to place myBits inside of result
 int shift = bitsLeft - size ; assert shift >= 0 ; // put it there
 result |= myBits << shift ; // -- put bit to result ----------------------
 // update information on what we consumed
 bitsLeft -= size ; bitPos -= size ; } return result ; }
Read the next nb bits and return an Unsigned Long .

@param nb the number of bits to convert to int, must be 0 <= nb <= 64.
@return result
@throws java.io.IOException on read error
Read the next nb bits and return an Unsigned Long .