### Question:
HexUtil { public static byte[] toBytesFromHex(String hexStr) { if (hexStr == null || hexStr.length() == 0) { return new byte[] {}; } if (hexStr.length() % 2 != 0) { hexStr += '0'; } int byteIndex = 0; final byte[] bytes = new byte[hexStr.length() / 2]; for (int i = 0; i < hexStr.length(); i += 2) { char upper = hexStr.charAt(i); char lower = hexStr.charAt(i + 1); bytes[byteIndex] = toByteFromHex(upper, lower); byteIndex++; } return bytes; }  static String toHexFromByte(final byte b); static byte toByteFromHex(char upperChar, char lowerChar); static String toHexFromBytes(final ByteBuffer bytes); static String toHexFromBytes(final byte[] bytes); static byte[] toBytesFromHex(String hexStr); final static int BITS_PER_HEX_DIGIT; }### Answer:
@Test public void testBytesToHex() { byte[] bytes = { (byte)0x0a, (byte)0xff, (byte)0x12, (byte)0x38, (byte)0xde, (byte)0xad, (byte)0xbe, (byte)0xef, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xde, (byte)0xad, (byte)0xc0, (byte)0xde }; String hex = "0aff1238deadbeef00000000deadc0de"; Assert.assertTrue(Arrays.equals(bytes, HexUtil.toBytesFromHex(hex))); hex = "54321"; Assert.assertTrue(Arrays.equals(new byte[] { (byte)0x54, (byte)0x32, (byte)0x10 }, HexUtil.toBytesFromHex(hex))); hex = "a"; Assert.assertTrue(Arrays.equals(new byte[] { (byte)0xa0 }, HexUtil.toBytesFromHex(hex))); Assert.assertTrue(Arrays.equals(new byte[] { }, HexUtil.toBytesFromHex(""))); Assert.assertTrue(Arrays.equals(new byte[] { }, HexUtil.toBytesFromHex(null))); }