public static byte[] decodeHex(final String data) {

        checkNotNull("data", data);

        final int len = data.length();

        if ((len & 0x01) != 0) {
            throw new RuntimeException("Odd number of characters.");
        }

        final byte[] out = new byte[len >> 1];

        // two characters form the hex value.
        for (int i = 0, j = 0; j < len; i++) {
            int f = toDigit(data.charAt(j), j) << 4;
            j++;
            f = f | toDigit(data.charAt(j), j);
            j++;
            out[i] = (byte) (f & 0xFF);
        }

        return out;
    }
public static byte [ ] decodeHex ( final String data ) { checkNotNull ( "data" , data ) ; final int len = data . length ( ) ; if ( ( len & 0x01 ) != 0 ) { throw new RuntimeException ( "Odd number of characters." ) ; } final byte [ ] out = new byte [ len > > 1 ] ; for ( int i = 0 , j = 0 ; j < len ; i ++ ) { int f = toDigit ( data . charAt ( j ) , j ) << 4 ; j ++ ; f = f | toDigit ( data . charAt ( j ) , j ) ; j ++ ; out [ i ] = ( byte ) ( f & 0xFF ) ; } return out ; }
CHECKSTYLE:OFF Orginal Apache code