Here you can find the source of hexStringToBytes(String hex)
public static byte[] hexStringToBytes(String hex)
//package com.java2s; public class Main { public static byte[] hexStringToBytes(String hex) { int len = hex.length() / 2; byte[] result = new byte[len]; char[] achar = hex.toCharArray(); for (int i = 0; i < len; i++) { int pos = i * 2; byte b1 = (byte) "0123456789ABCDEF".indexOf(achar[pos]); byte b2 = (byte) "0123456789ABCDEF".indexOf(achar[(pos + 1)]); result[i] = (byte) (b1 << 4 | b2); }//from ww w . j a va 2s . com return result; } }