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

StringgetStringForByte(byte[] bs)
get String For Byte
if (bs == null)
    return "";
try {
    return new String(bs, "UTF-8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return "";
...
StringfromBytes(byte abyte0[])
from Bytes
StringBuffer stringbuffer = new StringBuffer("");
int i = 0;
do {
    int j = abyte0.length;
    if (i < j) {
        int k = abyte0[i];
        if (k < 0)
            k += 256;
...
StringtoString(byte[] b, int start, int end)
Convert the bytes within the specified range of the given byte array into a String.
int size = end - start;
char[] theChars = new char[size];
for (int i = 0, j = start; i < size;)
    theChars[i++] = (char) (b[j++] & 0xff);
return new String(theChars);
StringBcd2Str(byte[] b)
Bcd Str
StringBuffer sb = new StringBuffer(b.length * 2);
for (int i = 0; i < b.length; i++) {
    sb.append((byte) (b[i] & 0xF0) >> 4);
    sb.append((byte) (b[i] & 0x0F));
return sb.toString().substring(0, 1).equalsIgnoreCase("0") ? sb
        .toString().substring(1) : sb.toString();
StringByteArrayToString(byte[] input)
Byte Array To String
if (input == null)
    return null;
else
    return new String(input, Charset.forName("utf-8"));
StringbyteArrayToString(byte[] b)
byte Array To String
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
    resultSb.append(byteToHexString(b[i]));
return resultSb.toString();
StringbyteArrayToString(byte[] bytes)
byte Array To String
StringBuilder buffer = new StringBuilder();
boolean isFirst = true;
for (byte b : bytes) {
    if (isFirst) {
        isFirst = false;
    } else {
        buffer.append("-");
    buffer.append(byteToString(b));
return buffer.toString();
StringbyteToString(byte b)
byte To String
String s = Integer.toHexString(b & 0xff).toUpperCase();
if (s.length() > 1) {
    return s;
} else {
    return "0" + s;
Stringbytes2String(byte[] data)
bytes String
String result = null;
int availableLen = data.length;
for (int i = 0; i < availableLen; i++) {
    if (data[i] == 0) {
        availableLen = i;
        break;
try {
    if (availableLen == 1) {
        result = String.valueOf((int) data[0]);
    } else {
        result = new String(data, 0, availableLen, "UTF-8");
} catch (UnsupportedEncodingException e) {
    return null;
return result;
Stringbytes2String(byte[] data, String type)
bytes String
if (type == null) {
    type = "";
StringBuffer sb = new StringBuffer();
System.out.println();
for (int i = 0; i < data.length; i++) {
    if ("".equals(type)) {
        sb.append(String.format("%02x", data[i]));
...