Revision as of 04:30, 23 November 2010 by Han84 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
/**
 * 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);
}


Back to JavaHowTo

Alumni Liaison

Ph.D. on Applied Mathematics in Aug 2007. Involved on applications of image super-resolution to electron microscopy

Francisco Blanco-Silva