ByteUtils { public static boolean isBitSet(int position, byte[] array) throws IllegalArgumentException { if (position < 0 || position >= array.length * 8) { throw new IllegalArgumentException("Position is invalid"); } return ((array[position / 8] & (128 >> (position % 8))) > 0); }  static byte[] clone(@Nullable byte[] input); static byte[] concatenate(byte[] x, byte[] y); static byte[] concatenate(byte x, byte[] y); static byte[] concatenate(byte[] x, byte y); static byte[] concatenate(byte x, byte y); static byte[] cutLeadingNullBytes(byte[] input); static byte[] cutLeadingNullByte(byte[] input); static byte[] copy(byte[] input, int offset, int length); static boolean compare(byte[] x, byte[] y); static boolean compare(byte x, byte[] y); static boolean compare(byte[] x, byte y); static boolean compare(byte x, byte y); static boolean isPrefix(byte[] prefix, byte[] data); static boolean isPrefix(byte prefix, byte[] data); static byte[] reverse(byte[] in); static String toHexString(@Nullable byte[] bytes); static String toHexString(@Nullable byte[] bytes, boolean formatted); static String toHexString(@Nullable byte[] bytes, boolean formatted, boolean addLinebreak); static String toFileSafeBase64String(@Nullable byte[] bytes); static String toWebSafeBase64String(@Nullable byte[] bytes); static String toFileSafeBase64String(@Nullable byte[] bytes, boolean withPadding); static short toShort(byte[] bytes); static short toShort(byte[] bytes, boolean bigEndian); static int toInteger(byte[] bytes); static int toInteger(byte[] bytes, boolean bigEndian); static long toLong(byte[] bytes); static long toLong(byte[] bytes, boolean bigEndian); static boolean isBitSet(int position, byte[] array); static void setBit(int position, byte[] array);  }
@Test public void testIsBitSet() { byte[] input = new byte[] { 0x00, 0x00, 0x08, 0x00, 0x00 }; assertTrue(ByteUtils.isBitSet(20, input)); assertFalse(ByteUtils.isBitSet(22, input)); try { ByteUtils.isBitSet(99, input); fail("An IndexOutOfBoundsException should have been thrown."); } catch (IllegalArgumentException e) { } try { ByteUtils.isBitSet(-6, input); fail("An IllegalArgumentException should have been thrown."); } catch (IllegalArgumentException e) { } }