(New page: <source lang="java"> →* * Represent the byte array into hex digits. Two hex digits represent one byte. * @param data * @param length * @return: public static String convertByteArra...) |
|||
Line 15: | Line 15: | ||
} | } | ||
return buf.toString(); | return buf.toString(); | ||
+ | } | ||
+ | |||
+ | public static String convertByteArrayToHex(byte[] data) { | ||
+ | return convertByteArrayToHex(data, data.length); | ||
} | } | ||
</source> | </source> |
Latest revision as of 04:30, 23 November 2010
/** * 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); }