Java Utililty Methods Byte Array to String

List of utility methods to do Byte Array to String

Description

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

Method

StringbyteToString(byte[] data)
Array of characters is converted to a string
if (data == null)
    return null;
String result = "";
for (int k = 0; k < data.length; k++) {
    result += Character.toString((char) (data[k]));
return result;
StringbytetoString(byte[] digest)
byteto String
String str = "";
String tempStr = "";
for (int i = 0; i < digest.length; i++) {
    tempStr = (Integer.toHexString(digest[i] & 0xff));
    if (tempStr.length() == 1) {
        str = str + "0" + tempStr;
    } else {
        str = str + tempStr;
...
StringbyteToString(byte[] input)
Creates a string
return new String(input);
StringbytetoString(byte[] tb)
byteto String
StringBuffer tsb = new StringBuffer();
for (int i = 0; i < tb.length; i++) {
    tsb.append(Integer.toHexString((int) tb[i]));
return tsb.toString();
StringbyteToString(final boolean prettyPrint, int byteValue)
Returns a byte value as either a 2-char hex string, or if pretty printing, and the byte value is a printable ASCII character, as a quoted ASCII char, unless it is a single quote character itself, in which case it will still be represented as a hex byte.
String result = null;
if (prettyPrint) {
    if (byteValue >= START_PRINTABLE_ASCII && byteValue <= END_PRINTABLE_ASCII
            && byteValue != QUOTE_CHARACTER_VALUE) {
        result = String.format(" '%c' ", byteValue);
    } else {
        result = String.format(" %02x ", byteValue);
} else {
    result = String.format("%02x", byteValue);
return result;
StringbyteToString(int[] byteData)
Chang the bit(it's length = 64) into the string.
StringBuilder str = new StringBuilder();
for (int i = 0; i < 4; i++) {
    int count = 0;
    for (int j = 0; j < 16; j++) {
        int pow = 1;
        for (int m = 15; m > j; m--) {
            pow *= 2;
        count += byteData[16 * i + j] * pow;
    if (count != 0) {
        str.append((char) (count));
return str.toString();