public static Binary fromHexString(String hex) {
        if (hex.length() % 2 != 0) {
            throw new IllegalArgumentException("Illegal hex string length: " + hex.length());
        }
        final int len = hex.length() / 2;
        final byte[] out = new byte[len];
        for (int i = 0; i < len; ++i) {
            int pos = i * 2;
            String part = hex.substring(pos, pos + 2);
            out[i] = (byte) Integer.parseInt(part, 16);
        }
        return Binary.wrap(out);
    }
public static Binary fromHexString ( String hex ) { if ( hex . length ( ) % 2 != 0 ) { throw new IllegalArgumentException ( "Illegal hex string length: " + hex . length ( ) ) ; } final int len = hex . length ( ) / 2 ; final byte [ ] out = new byte [ len ] ; for ( int i = 0 ; i < len ; ++ i ) { int pos = i * 2 ; String part = hex . substring ( pos , pos + 2 ) ; out [ i ] = ( byte ) Integer . parseInt ( part , 16 ) ; } return Binary . wrap ( out ) ; }
Parse a hex string as bytes.

@param hex The hex string.
@return The corresponding bytes.