public byte[] convertHexStringToBinary(String hexString) throws IllegalArgumentException {
  int length=hexString.length();
  if (length % 2 != 0) {
    throw new IllegalArgumentException("The provided hex String must be an even length, but was of length " + length + ": "+ hexString);
  }
  byte[] binary=new byte[length / 2];
  for (int i=0; i < length; i+=2) {
    char highBitsChar=hexString.charAt(i);
    char lowBitsChar=hexString.charAt(i + 1);
    int highBits=hexCharToInt(highBitsChar,hexString) << 4;
    int lowBits=hexCharToInt(lowBitsChar,hexString);
    binary[i / 2]=(byte)(highBits + lowBits);
  }
  return binary;
}

public byte [ ] convertHexStringToBinary ( String hexString ) throws IllegalArgumentException { int length = hexString . length ( ) ; if ( length % 2 != 0 ) { throw new IllegalArgumentException ( "The provided hex String must be an even length, but was of length " + length + ": " + hexString ) ; } byte [ ] binary = new byte [ length / 2 ] ; for ( int i = 0 ; i < length ; i += 2 ) { char highBitsChar = hexString . charAt ( i ) ; char lowBitsChar = hexString . charAt ( i + 1 ) ; int highBits = hexCharToInt ( highBitsChar , hexString ) << 4 ; int lowBits = hexCharToInt ( lowBitsChar , hexString ) ; binary [ i / 2 ] = ( byte ) ( highBits + lowBits ) ; } return binary ; }
convert the provided hex - string into a binary representation where each byte represents two characters of the hex string . < p > the hex characters may be upper or lower case .
