/** * Take the incoming character of hex encoded data and convert to the raw byte values. * <p> * The characters in the incoming array are processed in pairs with two chars of a pair * being converted to a single byte. * * @param toConvert - the hex encoded String to convert. * @return the raw byte array. */ public static byte[] convertFromHex(final char[] toConvert) { if (toConvert.length % 2 != 0) { throw new IllegalArgumentException("The supplied character array must contain an even number of hex chars."); } byte[] response = new byte[toConvert.length / 2]; for (int i = 0; i < response.length; i++) { int posOne = i * 2; response[i] = (byte)(toByte(toConvert, posOne) << 4 | toByte(toConvert, posOne+1)); } return response; }