[Java] Convert Hex to String

<code>
public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i &lt; len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) &lt;&lt; 4)
          + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}
</code>

stackoverflow: Convert a string representation of a hex dump to a byte array using Java?

This entry was posted in Java. Bookmark the permalink.