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)('0' + d1));
 else     sb.append((char)('a' + d1 - 10));
    if (d2 < 10)     sb.append((char)('0' + d2));
 else     sb.append((char)('a' + d2 - 10));
  }
  return sb.toString();
}

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 ) ( '0' + d1 ) ) ; else sb . append ( ( char ) ( 'a' + d1 - 10 ) ) ; if ( d2 < 10 ) sb . append ( ( char ) ( '0' + d2 ) ) ; else sb . append ( ( char ) ( 'a' + d2 - 10 ) ) ; } return sb . toString ( ) ; }
convert bytes to hex
