@Test public void test2() { BitBuffer bitbuf = new BitBuffer(new byte[] { (byte) 0xE0, 0x7A }, 0); assertEquals(14, bitbuf.getBits(4)); }
public long getBits(int numBits) { if (numBits > 64) { throw new IllegalArgumentException("Invalid numBits " + numBits + " max value: 64"); } if (byteOrder == ByteOrder.LITTLE_ENDIAN) { return getBitsLE(numBits); } long r = 0; int bytepos = position >> 3; int n = numBits; int fbb = -position & 0x7; if (fbb > 0) { if (n <= fbb) { position += numBits; return (b[idx(bytepos)] >>> (fbb - n)) & ((1 << n) - 1); } else { r = b[idx(bytepos)] & ((1 << fbb) - 1); n -= fbb; bytepos++; } } while (n > 8) { r = (r << 8) | (b[idx(bytepos)] & 0xFF); n -= 8; bytepos++; } r = (r << n) | ((b[idx(bytepos)] & 0xFF) >>> (8 - n)); position += numBits; return r; }
BitBuffer { public long getBits(int numBits) { if (numBits > 64) { throw new IllegalArgumentException("Invalid numBits " + numBits + " max value: 64"); } if (byteOrder == ByteOrder.LITTLE_ENDIAN) { return getBitsLE(numBits); } long r = 0; int bytepos = position >> 3; int n = numBits; int fbb = -position & 0x7; if (fbb > 0) { if (n <= fbb) { position += numBits; return (b[idx(bytepos)] >>> (fbb - n)) & ((1 << n) - 1); } else { r = b[idx(bytepos)] & ((1 << fbb) - 1); n -= fbb; bytepos++; } } while (n > 8) { r = (r << 8) | (b[idx(bytepos)] & 0xFF); n -= 8; bytepos++; } r = (r << n) | ((b[idx(bytepos)] & 0xFF) >>> (8 - n)); position += numBits; return r; } }
BitBuffer { public long getBits(int numBits) { if (numBits > 64) { throw new IllegalArgumentException("Invalid numBits " + numBits + " max value: 64"); } if (byteOrder == ByteOrder.LITTLE_ENDIAN) { return getBitsLE(numBits); } long r = 0; int bytepos = position >> 3; int n = numBits; int fbb = -position & 0x7; if (fbb > 0) { if (n <= fbb) { position += numBits; return (b[idx(bytepos)] >>> (fbb - n)) & ((1 << n) - 1); } else { r = b[idx(bytepos)] & ((1 << fbb) - 1); n -= fbb; bytepos++; } } while (n > 8) { r = (r << 8) | (b[idx(bytepos)] & 0xFF); n -= 8; bytepos++; } r = (r << n) | ((b[idx(bytepos)] & 0xFF) >>> (8 - n)); position += numBits; return r; } BitBuffer(byte[] b);  BitBuffer(byte[] b, int offset); }
BitBuffer { public long getBits(int numBits) { if (numBits > 64) { throw new IllegalArgumentException("Invalid numBits " + numBits + " max value: 64"); } if (byteOrder == ByteOrder.LITTLE_ENDIAN) { return getBitsLE(numBits); } long r = 0; int bytepos = position >> 3; int n = numBits; int fbb = -position & 0x7; if (fbb > 0) { if (n <= fbb) { position += numBits; return (b[idx(bytepos)] >>> (fbb - n)) & ((1 << n) - 1); } else { r = b[idx(bytepos)] & ((1 << fbb) - 1); n -= fbb; bytepos++; } } while (n > 8) { r = (r << 8) | (b[idx(bytepos)] & 0xFF); n -= 8; bytepos++; } r = (r << n) | ((b[idx(bytepos)] & 0xFF) >>> (8 - n)); position += numBits; return r; } BitBuffer(byte[] b);  BitBuffer(byte[] b, int offset); long getBits(int numBits); void putBits(long value, int numBits); void put(byte[] src, int offset, int length); void put(byte[] src); void putByte(byte c); int getPosition(); void setPosition(int position); void setByteOrder(ByteOrder order); ByteOrder getByteOrder(); byte getByte(); void getByteArray(byte[] dst); int sizeInBits(); int arrayLength(); BitBuffer slice(); byte[] array(); int offset(); int remainingBytes(); void skip(int numBits); }
BitBuffer { public long getBits(int numBits) { if (numBits > 64) { throw new IllegalArgumentException("Invalid numBits " + numBits + " max value: 64"); } if (byteOrder == ByteOrder.LITTLE_ENDIAN) { return getBitsLE(numBits); } long r = 0; int bytepos = position >> 3; int n = numBits; int fbb = -position & 0x7; if (fbb > 0) { if (n <= fbb) { position += numBits; return (b[idx(bytepos)] >>> (fbb - n)) & ((1 << n) - 1); } else { r = b[idx(bytepos)] & ((1 << fbb) - 1); n -= fbb; bytepos++; } } while (n > 8) { r = (r << 8) | (b[idx(bytepos)] & 0xFF); n -= 8; bytepos++; } r = (r << n) | ((b[idx(bytepos)] & 0xFF) >>> (8 - n)); position += numBits; return r; } BitBuffer(byte[] b);  BitBuffer(byte[] b, int offset); long getBits(int numBits); void putBits(long value, int numBits); void put(byte[] src, int offset, int length); void put(byte[] src); void putByte(byte c); int getPosition(); void setPosition(int position); void setByteOrder(ByteOrder order); ByteOrder getByteOrder(); byte getByte(); void getByteArray(byte[] dst); int sizeInBits(); int arrayLength(); BitBuffer slice(); byte[] array(); int offset(); int remainingBytes(); void skip(int numBits);  }