Java tutorial
//package com.java2s; public class Main { public static byte[] hexStringToByteArray(String paramString) { int j = paramString.length(); byte[] arrayOfByte = new byte[j / 2]; int i = 0; for (;;) { if (i >= j) { return arrayOfByte; } arrayOfByte[(i / 2)] = ((byte) ((Character.digit(paramString.charAt(i), 16) << 4) + Character.digit(paramString.charAt(i + 1), 16))); i += 2; } } }