public static String toHex ( byte [ ] bytes , int offset , int len ) { if ( bytes == null ) return "null" ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < len ; i ++ ) { int d1 = ( bytes [ offset + i ] >> 4 ) & 0xf ; int d2 = ( bytes [ offset + i ] ) & 0xf ; if ( d1 < 10 ) sb . append ( ( char ) ( ' ' + d1 ) ) ; else sb . append ( ( char ) ( ' ' + d1 - 10 ) ) ; if ( d2 < 10 ) sb . append ( ( char ) ( ' ' + d2 ) ) ; else sb . append ( ( char ) ( ' ' + d2 - 10 ) ) ; } return sb . toString ( ) ; }
Convert bytes to hex