public static byte [ ] convertHexStringToBytes ( String hexString , int offset , int endIndex ) { byte [ ] data ; String realHexString = hexString . substring ( offset , endIndex ) . toLowerCase ( ) ; if ( ( realHexString . length ( ) % 2 ) == 0 ) data = new byte [ realHexString . length ( ) / 2 ] ; else data = new byte [ ( int ) Math . ceil ( realHexString . length ( ) / 2d ) ] ; int j = 0 ; char [ ] tmp ; for ( int i = 0 ; i < realHexString . length ( ) ; i += 2 ) { try { tmp = realHexString . substring ( i , i + 2 ) . toCharArray ( ) ; } catch ( StringIndexOutOfBoundsException siob ) { // it only contains one character, so add "0" string tmp = ( realHexString . substring ( i ) + "0" ) . toCharArray ( ) ; } data [ j ] = ( byte ) ( ( Arrays . binarySearch ( hexChar , tmp [ 0 ] ) & 0xf ) << 4 ) ; data [ j ++ ] |= ( byte ) ( Arrays . binarySearch ( hexChar , tmp [ 1 ] ) & 0xf ) ; } for ( int i = realHexString . length ( ) ; i > 0 ; i -= 2 ) { } return data ; }
Convert the hex string to bytes .