/**
* Fast convert a byte array to a hex string
* with possible leading zero.
* @param b array of bytes to convert to string
* @return hex representation, two chars per byte.
*/
public static String toHexString ( byte[] b )
{
StringBuilder sb = new StringBuilder( b.length * 2 );
for ( byte b8 : b )
{
sb.append( hexChar [( b8 & 0xf0 ) >>> 4] );
sb.append( hexChar [b8 & 0x0f] );
}
return sb.toString();
}
/**
* table to convert a nibble to a hex char.
*/
final static char[] hexChar = {
'0' , '1' , '2' , '3' ,
'4' , '5' , '6' , '7' ,
'8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f'};