Java tutorial
//package com.java2s; public class Main { public static final int FIFTH_BITMASK = 16; public static final int FIRST_BITMASK = 1; public static final int SECOND_BITMASK = 2; public static final int THIRD_BITMASK = 4; public static byte[] hexStringToByteArray(String hexString) { int len = hexString.length(); byte[] data = new byte[(len / SECOND_BITMASK)]; for (int i = 0; i < len; i += SECOND_BITMASK) { data[i / SECOND_BITMASK] = (byte) ((Character.digit(hexString.charAt(i), FIFTH_BITMASK) << THIRD_BITMASK) + Character.digit(hexString.charAt(i + FIRST_BITMASK), FIFTH_BITMASK)); } return data; } }