Convert Byte Array To Hexadecimal String

Convert Byte Array To Hexadecimal String.

Javadoc available at https://www.javatapas.com/docs/javatapas/string/ConvertByteArrayToHexString.html


private static String convertByteArrayToHexString1(byte[] inBytes) {

	StringBuffer strbuf = new StringBuffer();

	for (byte b : inBytes) {strbuf.append(String.format("%02x", b));}

  return strbuf.toString();

}

public static String convertByteArrayToHexString2(byte inBytes[]) {

 StringBuffer strbuf = new StringBuffer(inBytes.length * 2);

 for (int i = 0; i < inBytes.length; i++) {
   if (((int) inBytes[i] & 0xff) < 0x10){strbuf.append("0");}
   strbuf.append(Long.toString((int) inBytes[i] & 0xff, 16));
 }

 return strbuf.toString();

}