public static byte[] hexStringToByte(String hex){
  byte[] bts=new byte[hex.length() / 2];
  for (int i=0; i < bts.length; i++) {
    bts[i]=(byte)Integer.parseInt(hex.substring(2 * i,2 * i + 2),16);
  }
  return bts;
}

public static byte [ ] hexStringToByte ( String hex ) { byte [ ] bts = new byte [ hex . length ( ) / 2 ] ; for ( int i = 0 ; i < bts . length ; i ++ ) { bts [ i ] = ( byte ) Integer . parseInt ( hex . substring ( 2 * i , 2 * i + 2 ) , 16 ) ; } return bts ; }
given a hexstring this will return the byte array corresponding to the string
