Java tutorial
//package com.java2s; import java.io.IOException; public class Main { /** * Decodes HEX representation of the string. * * @param data HEX * @return String representation of the {@code data} * @throws IOException if some error occurs */ private static String decodeHex(String data) throws IOException { if (data == null || data.isEmpty()) { return data; } if (data.length() % 2 != 0) { throw new IOException("String is not in hexadecimal representation."); } byte[] bytes = new byte[data.length() / 2]; for (int i = 0; i < data.length(); i += 2) { bytes[i / 2] = Integer.valueOf(data.substring(i, i + 2), 16).byteValue(); } return new String(bytes, "UTF-8"); } }