/** * Represent the byte array into hex digits. Two hex digits represent one byte. * @param data * @param length * @return */ public static String convertByteArrayToHex(byte[] data, int length) { String digits = "0123456789abcdef"; StringBuilder buf = new StringBuilder(); for (int i = 0; i != length; i++) { int v = data[i] & 0xff; buf.append(digits.charAt(v >> 4)); buf.append(digits.charAt(v & 0xf)); } return buf.toString(); } public static String convertByteArrayToHex(byte[] data) { return convertByteArrayToHex(data, data.length); }