Here you can find the source of hexStringToByteArray(String hexa)
public static byte[] hexStringToByteArray(String hexa) throws IllegalArgumentException
//package com.java2s; public class Main { private static final String hexDigits = "0123456789abcdef"; public static byte[] hexStringToByteArray(String hexa) throws IllegalArgumentException { //verifica se a String possui uma quantidade par de elementos if (hexa.length() % 2 != 0) { throw new IllegalArgumentException("String hexa inv?lida"); }/*w w w .ja va 2s .com*/ byte[] b = new byte[hexa.length() / 2]; for (int i = 0; i < hexa.length(); i += 2) { b[i / 2] = (byte) ((hexDigits.indexOf(hexa.charAt(i)) << 4) | (hexDigits .indexOf(hexa.charAt(i + 1)))); } return b; } }