question: public static byte [ ] fromHexString ( String text ) { text = text . trim ( ) ; if ( text . length ( ) % 2 != 0 ) text = "0" + text ; int resLen = text . length ( ) / 2 ; int loNibble , hiNibble ; byte [ ] res = new byte [ resLen ] ; for ( int i = 0 ; i < resLen ; i ++ ) { int j = i << 1 ; hiNibble = charToNibble ( text . charAt ( j ) ) ; loNibble = charToNibble ( text . charAt ( j + 1 ) ) ; if ( loNibble == - 1 || hiNibble == - 1 ) return null ; res [ i ] = ( byte ) ( hiNibble << 4 | loNibble ) ; } return res ; }
target:  Convert a String containing consecutive (no inside whitespace) hexadecimal digits into a corresponding byte array. If the number of digits is not even, a '0' will be appended in the front of the String prior to conversion. Leading and trailing whitespace is ignored.