@Test
public void testGetBits() throws Exception {

    byte[] data = { 10, 12, 14, 20, 55, 69, 82, 97, 109, 117, 127, -50 };
    byte[] bits;
    bits = BitBufferHelper.getBits(data, 88, 8); // BYTE extraOffsetBits = extranumBits = 0
    Assert.assertTrue(bits[0] == -50);
    bits = BitBufferHelper.getBits(data, 8, 16); // Short
    Assert.assertTrue(bits[0] == 12);
    Assert.assertTrue(bits[1] == 14);
    bits = BitBufferHelper.getBits(data, 32, 32); // Int
    Assert.assertTrue(bits[0] == 55);
    Assert.assertTrue(bits[1] == 69);
    Assert.assertTrue(bits[2] == 82);
    Assert.assertTrue(bits[3] == 97);
    bits = BitBufferHelper.getBits(data, 16, 48); // Long
    Assert.assertTrue(bits[0] == 14);
    Assert.assertTrue(bits[1] == 20);
    Assert.assertTrue(bits[2] == 55);
    Assert.assertTrue(bits[3] == 69);
    Assert.assertTrue(bits[4] == 82);
    Assert.assertTrue(bits[5] == 97);
    bits = BitBufferHelper.getBits(data, 40, 7); // BYTE extraOffsetBits = extranumBits != 0
    Assert.assertTrue(bits[0] == 34);
    bits = BitBufferHelper.getBits(data, 8, 13); // Short
    Assert.assertTrue(bits[0] == 1);
    Assert.assertTrue(bits[1] == -127);
    bits = BitBufferHelper.getBits(data, 32, 28); // Int
    Assert.assertTrue(bits[0] == 3);
    Assert.assertTrue(bits[1] == 116);
    Assert.assertTrue(bits[2] == 85);
    Assert.assertTrue(bits[3] == 38);
    bits = BitBufferHelper.getBits(data, 16, 41); // Long
    Assert.assertTrue(bits[0] == 0);
    Assert.assertTrue(bits[1] == 28);
    Assert.assertTrue(bits[2] == 40);
    Assert.assertTrue(bits[3] == 110);
    Assert.assertTrue(bits[4] == -118);
    Assert.assertTrue(bits[5] == -92);
    bits = BitBufferHelper.getBits(data, 3, 7); // BYTE extraOffsetBits != 0; extranumBits == 0
    Assert.assertTrue(bits[0] == 40);
    bits = BitBufferHelper.getBits(data, 13, 16); // Short
    Assert.assertTrue(bits[0] == -127);
    Assert.assertTrue(bits[1] == -62);
    bits = BitBufferHelper.getBits(data, 5, 32); // Int
    Assert.assertTrue(bits[0] == 65);
    Assert.assertTrue(bits[1] == -127);
    Assert.assertTrue(bits[2] == -62);
    Assert.assertTrue(bits[3] == -122);
    bits = BitBufferHelper.getBits(data, 23, 48); // Long
    Assert.assertTrue(bits[0] == 10);
    Assert.assertTrue(bits[1] == 27);
    Assert.assertTrue(bits[2] == -94);
    Assert.assertTrue(bits[3] == -87);
    Assert.assertTrue(bits[4] == 48);
    Assert.assertTrue(bits[5] == -74);
    bits = BitBufferHelper.getBits(data, 66, 9); // BYTE extraOffsetBits != 0; extranumBits != 0
    Assert.assertTrue(bits[0] == 1);
    Assert.assertTrue(bits[1] == 107);
    bits = BitBufferHelper.getBits(data, 13, 15); // Short
    Assert.assertTrue(bits[0] == 64);
    Assert.assertTrue(bits[1] == -31);
    bits = BitBufferHelper.getBits(data, 5, 29); // Int
    Assert.assertTrue(bits[0] == 8);
    Assert.assertTrue(bits[1] == 48);
    Assert.assertTrue(bits[2] == 56);
    Assert.assertTrue(bits[3] == 80);
    bits = BitBufferHelper.getBits(data, 31, 43); // Long
    Assert.assertTrue(bits[0] == 0);
    Assert.assertTrue(bits[1] == -35);
    Assert.assertTrue(bits[2] == 21);
    Assert.assertTrue(bits[3] == 73);
    Assert.assertTrue(bits[4] == -123);
    Assert.assertTrue(bits[5] == -75);
    bits = BitBufferHelper.getBits(data, 4, 12); // Short
    Assert.assertTrue(bits[0] == 10);
    Assert.assertTrue(bits[1] == 12);
    byte[] data1 = { 0, 8 };
    bits = BitBufferHelper.getBits(data1, 7, 9); // Short
    Assert.assertTrue(bits[0] == 0);
    Assert.assertTrue(bits[1] == 8);
    byte[] data2 = { 2, 8 };
    bits = BitBufferHelper.getBits(data2, 0, 7); // Short
    Assert.assertTrue(bits[0] == 1);
    bits = BitBufferHelper.getBits(data2, 7, 9); // Short
    Assert.assertTrue(bits[0] == 0);
    Assert.assertTrue(bits[1] == 8);
}