public static String toHex(byte[] bytes,int bytesPerRow){
  if (bytes == null)   return "(null)";
  StringBuffer sb=new StringBuffer();
  sb.append("[" + bytes.length + "] 0x");
  int i=0;
  while (i < bytes.length) {
    if (bytesPerRow > 0 && i % bytesPerRow == 0)     sb.append("\n");
    sb.append(HEX_CHARS[(bytes[i] >> 4) & 0x0F]);
    sb.append(HEX_CHARS[bytes[i] & 0x0F]);
    i++;
  }
  return sb.toString();
}

public static String toHex ( byte [ ] bytes , int bytesPerRow ) { if ( bytes == null ) return "(null)" ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( "[" + bytes . length + "] 0x" ) ; int i = 0 ; while ( i < bytes . length ) { if ( bytesPerRow > 0 && i % bytesPerRow == 0 ) sb . append ( "\n" ) ; sb . append ( HEX_CHARS [ ( bytes [ i ] > > 4 ) & 0x0F ] ) ; sb . append ( HEX_CHARS [ bytes [ i ] & 0x0F ] ) ; i ++ ; } return sb . toString ( ) ; }
convenience method for " displaying " a hex - string of a given byte array . breaks the string to lines , if bytesperrow > 0 .
