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

Stringbytes2HexString(byte... bytes)
Formats an array of bytes as a string showing values in hex.
return bytes2HexStringWithSeparator(":", bytes);
Stringbytes2HexString(byte[] array)
bytes Hex String
if (array == null || array.length == 0) {
    return null;
StringBuilder builder = new StringBuilder();
builder.append("[");
for (int i = 0; i < array.length; i++) {
    builder.append("0x");
    builder.append(byte2HexString(array[i]));
...
Stringbytes2HexString(byte[] b)
bytes Hex String
if (b.length == 0) {
    return null;
StringBuilder sb = new StringBuilder("");
for (int i = 0; i < b.length; i++) {
    int value = b[i] & 0xFF;
    String hv = Integer.toHexString(value);
    if (hv.length() < 2) {
...
Stringbytes2HexString(byte[] b)
bytes Hex String
StringBuilder sb = new StringBuilder(b.length << 2);
for (byte x : b) {
    int hi = (x & 0xf0) >> 4;
    int lo = x & 0x0f;
    sb.append(HEX_CHARS[hi]);
    sb.append(HEX_CHARS[lo]);
return sb.toString();
...
Stringbytes2HexString(byte[] b)
bytes Hex String
String ret = "";
for (int i = 0; i < b.length; i++) {
    String hex = Integer.toHexString(b[i] & 0xFF);
    if (hex.length() == 1) {
        hex = '0' + hex;
    ret += hex.toUpperCase();
return ret;
Stringbytes2HexString(byte[] bytes)
bytes Hex String
StringBuffer buffer = new StringBuffer();
int digital;
for (int i = 0; i < bytes.length; i++) {
    digital = bytes[i];
    if (digital < 0) {
        digital += 256;
    if (digital < 16) {
...
Stringbytes2HexString(byte[] bytes)
Converts an array of bytes to a string of two digits hex-representations
StringBuffer resultBuffer = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    resultBuffer.append(byte2Hex(bytes[i]));
return resultBuffer.toString();
Stringbytes2HexString(byte[] bytes)
Convert byte array to hex string.
StringBuffer sb = new StringBuffer(bytes.length);
String sTemp;
for (int i = 0; i < bytes.length; i++) {
    sTemp = Integer.toHexString(0xFF & bytes[i]);
    if (sTemp.length() < 2) {
        sb.append(0);
    sb.append(sTemp.toUpperCase());
...
Stringbytes2HexString(byte[] bytes)
bytes Hex String
if (bytes == null)
    return null;
int len = bytes.length;
if (len <= 0)
    return null;
char[] ret = new char[len << 1];
for (int i = 0, j = 0; i < len; i++) {
    ret[j++] = hexDigits[bytes[i] >>> 4 & 0x0f];
...
Stringbytes2HexString(byte[] src)
bytes Hex String
StringBuilder stringBuilder = new StringBuilder("");
if (null != src && src.length > 0) {
    for (int i = 0; i < src.length; i++) {
        int j = src[i] & 0xFF;
        String str = Integer.toHexString(j);
        if (str.length() < 2) {
            stringBuilder.append(0);
        stringBuilder.append(str);
    return stringBuilder.toString();
return null;