ByteArrayHelper { public static boolean getBit(byte[] input, int index) { if (index < 0) { throw new IllegalAccessError("Bit index must not be negative."); } byte currentByte = (byte) (input[index / 8] >> (7 - (index % 8))); boolean choiceBit = false; if ((currentByte & 1) == 1) { choiceBit = true; } return choiceBit; } private  ByteArrayHelper(); static boolean getBit(byte[] input, int index); static void setBit(byte[] input, int index, boolean choice); static void xor(List<byte[]> vector1, List<byte[]> vector2); static void xor(byte[] arr1, byte[] arr2); static void shiftArray(byte[] input, byte[] output, int positions);  }
@Test public void testGetBit() { byte[] byteArray = new byte[] { (byte) 0x54, (byte) 0x04 }; assertEquals(true, ByteArrayHelper.getBit(byteArray, 13)); byteArray = new byte[] { (byte) 0xFF, (byte) 0xFB }; assertEquals(false, ByteArrayHelper.getBit(byteArray, 13)); }
@Test(expected = IllegalAccessError.class) public void testGetBitIllegal() { ByteArrayHelper.getBit(new byte[]{}, -1); }