@Test(expected = IllegalArgumentException.class) public void testInvalidHexString() { final String hexString = "A9G0"; HexConverter.hexToBytes(hexString); }
public static byte[] hexToBytes(final String hexString) { if (hexString.length() % 2 != 0) { throw new IllegalArgumentException("Invalid number of digits: input must be a string of hexadecimal digit pairs"); } final byte[] bytes = new byte[hexString.length() / 2]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16); } return bytes; }
HexConverter { public static byte[] hexToBytes(final String hexString) { if (hexString.length() % 2 != 0) { throw new IllegalArgumentException("Invalid number of digits: input must be a string of hexadecimal digit pairs"); } final byte[] bytes = new byte[hexString.length() / 2]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16); } return bytes; } }
HexConverter { public static byte[] hexToBytes(final String hexString) { if (hexString.length() % 2 != 0) { throw new IllegalArgumentException("Invalid number of digits: input must be a string of hexadecimal digit pairs"); } final byte[] bytes = new byte[hexString.length() / 2]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16); } return bytes; } private  HexConverter(); }
HexConverter { public static byte[] hexToBytes(final String hexString) { if (hexString.length() % 2 != 0) { throw new IllegalArgumentException("Invalid number of digits: input must be a string of hexadecimal digit pairs"); } final byte[] bytes = new byte[hexString.length() / 2]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16); } return bytes; } private  HexConverter(); static String bytesToHex(final byte[] bytes); static byte[] hexToBytes(final String hexString); }
HexConverter { public static byte[] hexToBytes(final String hexString) { if (hexString.length() % 2 != 0) { throw new IllegalArgumentException("Invalid number of digits: input must be a string of hexadecimal digit pairs"); } final byte[] bytes = new byte[hexString.length() / 2]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16); } return bytes; } private  HexConverter(); static String bytesToHex(final byte[] bytes); static byte[] hexToBytes(final String hexString);  }