Android Utililty Methods Byte Array to String Convert

List of utility methods to do Byte Array to String Convert

Description

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

Method

voidbyteArray(StringBuilder buffer, byte[] bytes)
byte Array
for (int i = 0; i < bytes.length; i++) {
    buffer.append("b[").append(i).append("]=").append(bytes[i]);
    if (i < bytes.length - 1) {
        buffer.append(',');
intbyteArrayToInt(byte[] value, int offset)
byte Array To Int
return (int) (((int) value[0 + offset] << 24) & 0xFF000000)
        | (((int) value[1 + offset] << 16) & 0x00FF0000)
        | (((int) value[2 + offset] << 8) & 0x0000FF00)
        | ((int) value[3 + offset] & 0x000000FF);
shortbyteArrayToShort(byte[] value, int offset)
byte Array To Short
return (short) ((((short) value[0 + offset] << 8) & 0xFF00) | ((short) value[1 + offset] & 0x00FF));
StringbyteArrayToString(byte[] data)
Returns a (readable) String representation of the byte array
StringBuilder sb = new StringBuilder();
for (byte b : data) {
    sb.append(Integer.toString(b));
return sb.toString();
StringbyteArrayToString(byte[] data)
byte Array To String
return new String(Hex.encodeHex(data));
StringwriteByteArray(byte[] bytes)
write Byte Array
StringBuilder raw = new StringBuilder(String.format(Locale.US,
        "len %d: ", bytes.length));
for (int i = 0; i < bytes.length; i++)
    raw.append(String.format(Locale.US, "%X ", bytes[i]));
return raw.toString();