public static byte[] toByteArray(String spacedHex){
  int idx=0;
  final int len=spacedHex.length();
  final StringBuilder sb=new StringBuilder();
  final ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  while (idx < len) {
    final char chr=spacedHex.charAt(idx++);
    if (chr != ' ') {
      sb.setLength(0);
      sb.append(chr);
      sb.append(spacedHex.charAt(idx++));
      final int i=Integer.parseInt(sb.toString(),16);
      final byte b=((byte)i);
      bytes.write(b);
    }
  }
  return bytes.toByteArray();
}

public static byte [ ] toByteArray ( String spacedHex ) { int idx = 0 ; final int len = spacedHex . length ( ) ; final StringBuilder sb = new StringBuilder ( ) ; final ByteArrayOutputStream bytes = new ByteArrayOutputStream ( ) ; while ( idx < len ) { final char chr = spacedHex . charAt ( idx ++ ) ; if ( chr != ' ' ) { sb . setLength ( 0 ) ; sb . append ( chr ) ; sb . append ( spacedHex . charAt ( idx ++ ) ) ; final int i = Integer . parseInt ( sb . toString ( ) , 16 ) ; final byte b = ( ( byte ) i ) ; bytes . write ( b ) ; } } return bytes . toByteArray ( ) ; }
convert the spaced hex form of a string into a byte array .
