public static String asHex(byte[] bytes,String separator){
  StringBuilder sb=new StringBuilder();
  for (int i=0; i < bytes.length; i++) {
    String code=Integer.toHexString(bytes[i] & 0xFF);
    if ((bytes[i] & 0xFF) < 16) {
      sb.append('0');
    }
    sb.append(code);
    if (separator != null && i < bytes.length - 1) {
      sb.append(separator);
    }
  }
  return sb.toString();
}

public static String asHex ( byte [ ] bytes , String separator ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < bytes . length ; i ++ ) { String code = Integer . toHexString ( bytes [ i ] & 0xFF ) ; if ( ( bytes [ i ] & 0xFF ) < 16 ) { sb . append ( '0' ) ; } sb . append ( code ) ; if ( separator != null && i < bytes . length - 1 ) { sb . append ( separator ) ; } } return sb . toString ( ) ; }
returns a hexadecimal representation of the given byte array .
