Bytes { public static String toHex(byte b) { return String.format("%x", b); }  static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger, boolean bigEndian); static int[] toReducedBitIntArray(
            byte[] ba,
            final int amount,
            int bytePerInteger,
            int bitAmount,
            boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
@Test public void toHextTest() { assertEquals(toHex((byte) 0), "0"); assertEquals(toHex((byte) 1), "1"); assertEquals(toHex((byte) 15), "f"); assertEquals(toHex((byte) 127), "7f"); assertEquals(toHex((byte) 0xcc), "cc"); assertEquals(toHex(new byte[]{(byte) 0x01}), "1"); assertEquals(toHex(new byte[]{(byte) 0xcc}), "cc"); assertEquals(toHex(new byte[]{0x00, 0x00}), "0"); assertEquals(toHex(new byte[]{0x01, 0x1f, (byte) 0xcc}), "11fcc"); assertEquals(toHex(new byte[]{0x01, 0x1f, 0x00}), "11f00"); assertEquals(toHex(new byte[]{0x00, 0x01, 0x1f, 0x01, 0x00, 0x00}), "11f010000"); }
@Test(expected = NullPointerException.class) public void toHexExceptionTest() { toHex(null); }