Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static byte[] HexString2Bytes(String src) { int leng = src.length() / 2; byte[] ret = new byte[leng]; byte[] tmp = src.getBytes(); for (int i = 0; i < leng; i++) { ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]); } return ret; } public static byte uniteBytes(byte src0, byte src1) { byte _b0 = Byte.decode("0x" + new String(new byte[] { src0 })).byteValue(); _b0 = (byte) (_b0 << 4); byte _b1 = Byte.decode("0x" + new String(new byte[] { src1 })).byteValue(); byte ret = (byte) (_b0 ^ _b1); return ret; } }