Java Utililty Methods Byte to Hex String

List of utility methods to do Byte to Hex String

Description

The list of methods to do Byte to Hex String are organized into topic(s).

Method

StringbyteToHexString(final byte b)
Converts the given byte to a (zero-padded, if necessary) hex String .
final String s = Integer.toHexString(b & 0xff);
return (s.length() == 1) ? "0" + s : s;
StringbyteToHexString(final byte b)
Method to get a beautyfied representation of a byte as a hex string.
String hex = Integer.toHexString(0x0FF & b);
if (hex.length() == 1) {
    hex = "0" + hex;
return hex;
StringbyteToHexString(final byte inbyte)
convert the given byte to Hex String
String result = "0x";
if (inbyte <= Byte.MAX_VALUE && inbyte >= 0) {
    if (inbyte < 16) {
        result += "0";
    result += Integer.toHexString((int) inbyte);
} else {
    result += Integer.toHexString(0x100 + inbyte);
...
StringbyteToHexString(int b)
byte To Hex String
String s = Integer.toHexString(b & 0xFF);
if (s.length() == 1)
    return "0" + s;
else
    return s;
StringbyteToHexString(int nib1, int nib2)
Converts a single byte into a hexadecimal string.
char char1, char2;
char[] chars = new char[2];
char1 = nibbleToChar(nib1);
char2 = nibbleToChar(nib2);
chars[0] = char2;
chars[1] = char1;
return (new String(chars));
StringbyteToHexStringPadded(int value)
byte To Hex String Padded
return BYTE2HEX_PAD[value & 0xff];
StringbyteToHexStringSingle(byte[] byteArray)
byte To Hex String Single
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
    if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) {
        md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
    } else {
        md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
return md5StrBuff.toString();