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[] b)
bytes To Hex
StringBuilder sb = new StringBuilder();
for (int i = 0; i < b.length; i++) {
    sb.append(byteToHex(b[i])).append(" ");
return sb.toString();
StringbytesToHex(byte[] b, int offset, int length)
Converts a byte array to a hexadecimal string.
StringBuffer sb;
String result;
int i, top;
top = offset + length;
if (length < 0 || top > b.length)
    throw new IllegalArgumentException();
sb = new StringBuffer();
for (i = offset; i < top; i++) {
...
StringbytesToHex(byte[] binary)
Convert binary array to a hex string.
byte[] hex = new byte[binary.length * 2];
for (int i = 0; i < binary.length; i++) {
    hex[2 * i] = HexLookupTable[(binary[i] & 0xFF) >>> 4];
    hex[2 * i + 1] = HexLookupTable[binary[i] & 0xF];
return new String(hex);
StringbytesToHex(byte[] bs, int off, int length)
bytes To Hex
StringBuffer sb = new StringBuffer(length * 2);
bytesToHexAppend(bs, off, length, sb);
return sb.toString();
StringbytesToHex(byte[] bt)
bytes To Hex
StringBuilder stringBuilder = new StringBuilder();
if (bt == null || bt.length <= 0) {
    return null;
for (int i = 0; i < bt.length; i++) {
    int v = bt[i] & 0xFF;
    String hv = Integer.toHexString(v);
    if (hv.length() < 2) {
...
StringbytesToHex(byte[] buf)
bytes To Hex
final StringBuilder b = new StringBuilder(buf.length * 2);
for (int i = 0; i < buf.length; i++) {
    final int cell = (int) (buf[i] & 0xFF);
    if (cell < 16) {
        b.append("0");
    b.append(Integer.toString(cell, 16));
return b.toString();
StringbytesToHex(byte[] bytes)
bytes To Hex
return bytesToHex(bytes, 0, bytes.length);
StringbytesToHex(byte[] bytes)
Converts the provided byte array into a hexadecimal string with two characters per byte.
return bytesToHex(bytes, false);
StringbytesToHex(byte[] bytes)
bytes To Hex
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    String hex = Integer.toHexString(bytes[i] & 0xFF);
    if (hex.length() < 2) {
        hexString.append(0);
    hexString.append(hex);
return hexString.toString();
StringbytesToHex(byte[] bytes)
bytes To Hex
StringBuilder stringBuilder = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    String s = "0" + Integer.toHexString(bytes[i]);
    stringBuilder.append(s.substring(s.length() - 2, s.length()));
return stringBuilder.toString();