Android Byte Array to String Convert toText(byte[] arr)

Here you can find the source of toText(byte[] arr)

Description

To text?

License

Open Source License

Parameter

Parameter Description
arr a parameter

Declaration

public static String toText(byte[] arr) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w  ww .  ja v a  2s  .  co  m*/
     * To text?
     * @param arr
     * @return
     */
    public static String toText(byte[] arr) {
        String ret = "";
        if (arr != null && arr.length > 0) {
            for (int i = 0; i < arr.length; i++) {
                if (i > 0) {
                    ret += ".";
                }
                int b = toUnsignedInteger(arr[i]);
                ret += b;
            }
        }
        return ret;
    }

    /**
     * Convert byte to unsigned integer.
     * @param b
     * @return
     */
    public static int toUnsignedInteger(byte b) {
        int n = b >= 0 ? b : b + 256;
        return n;
    }
}

Related

  1. toStringWithLength(byte[] b, int pos, int length)
  2. printBytes(byte[] bytes, StringBuilder builder, int bytesPerLine)
  3. printBytes(byte[] bytes, int bytesPerLine)
  4. printBytes(byte[] data, String type)
  5. bytesToByteString(byte[] bytes)
  6. byteArray(StringBuilder buffer, byte[] bytes)
  7. byteArrayToInt(byte[] value, int offset)
  8. byteArrayToShort(byte[] value, int offset)
  9. byteArrayToString(byte[] data)