/**
  * convert a String to a hex representation of the String,
  * with 4 hex chars per char of the original String, broken into byte groups.
  * e.g. "1abc \uabcd" gives "0031_0061_0062_0063_0020_abcd"
  * @param s String to convert to hex equivalent
  * @return hex represenation of string, 4 hex digit chars per char.
  */
public static String displayHexString ( String s )
   {
   StringBuilder sb = new StringBuilder( s.length() * 5 - 1 );
   for ( int i=0; i<s.length(); i++ )
      {
      char c = s.charAt(i);
      if ( i != 0 )
         {
         sb.append( '_' );
         }
      // encode 16 bits as four nibbles

      sb.append( hexChar [ c >>> 12 & 0xf ] );
      sb.append( hexChar [ c >>> 8 & 0xf ] );
      sb.append( hexChar [ c >>> 4 & 0xf ] );
      sb.append( hexChar [ c & 0xf ] );
      }
   return sb.toString();
   }

/**
 * table to convert a nibble to a hex char.
 */
static final char[] hexChar = {
   '0' , '1' , '2' , '3' ,
   '4' , '5' , '6' , '7' ,
   '8' , '9' , 'a' , 'b' ,
   'c' , 'd' , 'e' , 'f'};