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

StringbytesToHex(byte[] bytes)
bytes To Hex
return bytesToHex(bytes, bytes.length);
StringbytesToHex(byte[] bytes)
bytes To Hex
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
    int v = bytes[j] & 0xFF;
    hexChars[j * 2] = hexArray[v >>> 4];
    hexChars[j * 2 + 1] = hexArray[v & 0x0F];
return new String(hexChars);
StringbytesToHex(byte[] bytes)
Helper method to convert a byte array to a hexadecimal string.
StringBuilder sb = new StringBuilder();
for (byte hashByte : bytes) {
    int intVal = 0xff & hashByte;
    if (intVal < 0x10) {
        sb.append('0');
    sb.append(Integer.toHexString(intVal));
return sb.toString();
StringbytesToHex(byte[] bytes)
translate a byte array of raw data into a String with a hex representation of that data
return bytesToHex(bytes, null);
StringbytesToHex(byte[] bytes)
Transforms byte to hex representation
StringBuilder buffer = new StringBuilder(2 * bytes.length);
for (int i = 0; i < bytes.length; ++i) {
    buffer.append(Character.forDigit((bytes[i] >> 4) & 0xF, 16));
    buffer.append(Character.forDigit(bytes[i] & 0xF, 16));
return buffer.toString();
StringbytesToHex(byte[] bytes)
bytes To Hex
return bytesToHex(bytes, false);
StringbytesToHex(byte[] bytes)
bytes To Hex
StringBuilder sb = new StringBuilder();
int t;
for (int i = 0; i < 16; i++) {
    t = bytes[i];
    if (t < 0) {
        t += 256;
    sb.append(hexDigits[(t >>> 4)]);
...
StringbytesToHex(byte[] bytes)
bytes To Hex
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
    sb.append(String.format("%02X ", b));
return sb.toString();
StringbytesToHex(byte[] bytes)
bytes To Hex
char[] hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++) {
    v = bytes[j] & 0xFF;
    hexChars[j * 2] = hexArray[v >>> 4];
    hexChars[j * 2 + 1] = hexArray[v & 0x0F];
return new String(hexChars);
...
StringbytesToHex(byte[] bytes)
bytes To Hex
char[] str = new char[bytes.length << 1];
for (int i = 0, j = 0; i < bytes.length; i++) {
    str[j++] = HEX[(bytes[i] & 0xf0) >>> 4];
    str[j++] = HEX[bytes[i] & 0x0f];
return new String(str);