question: public int rangeToInt ( int bitOffset , int numOfBits ) { int result = 0 ; int baseShift = numOfBits - 8 + bitOffset % 8 ; int byteIdx = bitOffset / 8 ; while ( baseShift >= 0 ) { result |= vector [ byteIdx ] << baseShift ; byteIdx ++ ; baseShift -= 8 ; } if ( baseShift < 0 ) result |= vector [ byteIdx ] > > > Math . abs ( baseShift ) ; result &= 0xFFFFFFFF > > > 32 - numOfBits ; return result ; }
target:  reads an arbitrary (even non-aligned) range of bits (up to 32) and interprets them as int (bigendian)