Java Utililty Methods Byte Array to Hex

List of utility methods to do Byte Array to Hex

Description

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

Method

StringbyteToHex(byte[] array, String separator)
Converts a byte array to a hex string.
assert array != null;
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < array.length; i++) {
    if (i != 0) {
        buffer.append(separator);
    if ((array[i] & 0xff) < 0x10) {
        buffer.append("0");
...
StringbyteToHex(byte[] b, int size)
byte To Hex
return byteToHex(b, size, true);
StringbyteToHex(byte[] base)
byte To Hex
char[] c = new char[base.length * 2];
int i = 0;
for (byte b : base) {
    int j = b;
    j = j + 128;
    c[i++] = TOHEX[j / 0x10];
    c[i++] = TOHEX[j % 0x10];
return new String(c);
StringbyteToHex(byte[] buf)
converting a byte[] to it's hexadecimal format String
if (buf == null)
    return null;
return byteToHex(buf, 0, buf.length);
StringbyteToHex(byte[] buffer)
byte To Hex
StringBuffer hexString = new StringBuffer();
String hex;
int iValue;
for (int i = 0; i < buffer.length; i++) {
    iValue = buffer[i];
    if (iValue < 0)
        iValue += 256;
    hex = Integer.toString(iValue, 16);
...
StringByteToHex(byte[] bytes)
Byte To Hex
StringBuffer sha1StrBuff = new StringBuffer();
for (int i = 0; i < bytes.length; ++i) {
    if (Integer.toHexString(255 & bytes[i]).length() == 1) {
        sha1StrBuff.append("0").append(Integer.toHexString(255 & bytes[i]));
    } else {
        sha1StrBuff.append(Integer.toHexString(255 & bytes[i]));
return sha1StrBuff.toString();
StringbyteToHex(byte[] content, int nLength)
byte To Hex
StringBuilder sb = new StringBuilder();
int nPos = 0;
while (nPos < nLength) {
    int nByteLength = sb.length();
    sb.append(toHex(content[nPos], 2)).append(" ");
    nPos++;
return sb.toString();
...
StringbyteToHex(byte[] raw)
byte To Hex
String hex_tab = "0123456789abcdef";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < raw.length; i++) {
    byte b = raw[i];
    sb.append(hex_tab.charAt((b & 0xF0) >> 4));
    sb.append(hex_tab.charAt(b & 0xF));
return sb.toString();
...
StringbyteToHex(final byte b)
byte To Hex
final char byteHexChar1 = HEX_CHARS[(b & 0xf0) >> 4];
final char byteHexChar2 = HEX_CHARS[b & 0x0f];
return byteHexChar1 + "" + byteHexChar2;
StringbyteToHex(final byte b)
Convert a byte into a hex string.
StringBuilder sb = new StringBuilder(2);
sb.append(hexChar[(b & 0xF0) >>> 4]);
sb.append(hexChar[b & 0x0F]);
return sb.toString();