public static byte [ ] hex2bin ( final String s ) { String m = s ; if ( s == null ) { // Allow empty input string. m = "" ; } else if ( s . length ( ) % 2 != 0 ) { // Assume leading zero for odd string length m = "0" + s ; } byte r [ ] = new byte [ m . length ( ) / 2 ] ; for ( int i = 0 , n = 0 ; i < m . length ( ) ; n ++ ) { char h = m . charAt ( i ++ ) ; char l = m . charAt ( i ++ ) ; r [ n ] = ( byte ) ( hex2bin ( h ) * 16 + hex2bin ( l ) ) ; } return r ; }
Convert hex string to array of bytes .