Convenience method to convert a byte to a hex string.
class Main{
/**
* Convenience method to convert a byte to a hex string.
*
* @param data
* the byte to convert
* @return String the converted byte
*/
publicstatic String byteToHex(byte data) {
StringBuffer buf = new StringBuffer();
buf.append(toHexChar((data >>> 4) & 0x0F));
buf.append(toHexChar(data & 0x0F));
return buf.toString();
}
/**
* Convenience method to convert an int to a hex char.
*
* @param i
* the int to convert
* @return char the converted char
*/
publicstaticchar toHexChar(int i) {
if ((0 <= i) && (i <= 9))
return (char) ('0' + i);
elsereturn (char) ('a' + (i - 10));
}
}