Java tutorial
//package com.java2s; import android.util.Log; public class Main { private static final String LOG_TAG = "MarvinMessaging"; public static byte[] hexStringToBytes(String hex) { byte[] bytes = new byte[hex.length() / 2]; int j = 0; for (int i = 0; i < hex.length(); i += 2) { try { String hexByte = hex.substring(i, i + 2); Integer I = new Integer(0); I = Integer.decode("0x" + hexByte); int k = I.intValue(); bytes[j++] = new Integer(k).byteValue(); } catch (NumberFormatException e) { Log.d(LOG_TAG, "hexStringToBytes", e); return bytes; } catch (StringIndexOutOfBoundsException e) { Log.d(LOG_TAG, "hexStringToBytes", e); return bytes; } } return bytes; } }