Here you can find the source of fromHex(String s)
public static byte[] fromHex(String s)
//package com.java2s; //License from project: Open Source License public class Main { public static byte[] fromHex(String s) { if (s.length() % 2 != 0) { throw new IllegalArgumentException("Hex " + s + " must be divisible by two"); }/*w w w . j a v a 2 s.c o m*/ byte[] bytes = new byte[s.length() / 2]; for (int i = 0; i < bytes.length; i++) { char left = s.charAt(i * 2); char right = s.charAt(i * 2 + 1); byte b = (byte) ((getValue(left) << 4) | (getValue(right) & 0xF)); bytes[i] = b; } return bytes; } private static int getValue(char c) { int i = Character.digit(c, 16); if (i < 0) { throw new IllegalArgumentException("Invalid hex char: " + c); } return i; } }