ByteUtils { public static byte[] reverse(byte[] input) { byte[] output = new byte[input.length]; int counter = 0; for (byte b : input) { output[input.length - counter - 1] = b; counter++; } return output; }  static byte[][] split(byte[] input, int firstLength); static byte[] reverse(byte[] input); static byte[] join(byte[] value1, byte[] value2); static byte[] join(byte[]... inputs); static byte[] paddingZeroOnHead(byte[] input, int byteLength); static byte[] paddingZeroOnTail(byte[] input, int byteLength); static int readBit(byte value, int position);  }
@Test public void success_reverse() { byte[] input = new byte[]{26, 94, 11, 65, 43, 13, 62, 53, 13, 43}; assertThat(ByteUtils.reverse(input), is(new byte[]{43, 13, 53, 62, 13, 43, 65, 11, 94, 26})); byte[] input2 = new byte[]{54, 25, 53, 91, 24, 42, 51, 51, 54, 41, 35, 30, 45, 14, 34, 53}; assertThat(ByteUtils.reverse(input2), is(new byte[]{53, 34, 14, 45, 30, 35, 41, 54, 51, 51, 42, 24, 91, 53, 25, 54})); }
@Test public void success_ReverseByteArrayToBigInteger() { byte[] input = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; byte[] input2 = new byte[]{31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; BigInteger integer1 = new BigInteger(input); BigInteger integer2 = new BigInteger(ByteUtils.reverse(input2)); assertEquals(integer1, integer2); }