Here you can find the source of toBytesFromHexString(String digits)
public static byte[] toBytesFromHexString(String digits) throws IllegalArgumentException, NumberFormatException
//package com.java2s; public class Main { public static byte[] toBytesFromHexString(String digits) throws IllegalArgumentException, NumberFormatException { if (digits == null) { return null; }/*from ww w. j a v a2 s.c o m*/ int length = digits.length(); if (length % 2 == 1) { throw new IllegalArgumentException("For input string: \"" + digits + "\""); } length = length / 2; byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { int index = i * 2; bytes[i] = (byte) (Short.parseShort( digits.substring(index, index + 2), 16)); } return bytes; } }