Java tutorial
//package com.java2s; public class Main { public static byte[] ascii2byte(String s) { try { char[] cs = s.toUpperCase().toCharArray(); byte[] bs = new byte[cs.length / 2]; for (int i = 0, n = bs.length; i < n; i++) { bs[i] = (byte) (((cs[i * 2] - 'A') << 4) | (cs[i * 2 + 1] - 'A')); } return bs; } catch (Exception e) { return null; } } }