Android Array to String Convert toString(byte[] ba)

Here you can find the source of toString(byte[] ba)

Description

to String

Declaration

public static final String toString(byte[] ba) 

Method Source Code

//package com.java2s;

public class Main {
    private static final char[] HEX_DIGITS = "0123456789ABCDEF"
            .toCharArray();//from w  w  w  .j  a v  a  2 s  .  co m

    public static final String toString(byte[] ba) {
        return toString(ba, 0, ba.length);
    }

    public static final String toString(byte[] ba, int offset, int length) {
        char[] buf = new char[length * 2];
        for (int i = 0, j = 0, k; i < length;) {
            k = ba[offset + i++];
            buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
            buf[j++] = HEX_DIGITS[k & 0x0F];
        }
        return new String(buf);
    }
}

Related

  1. toString(long[][] iArray)
  2. toString(Object[] obj)
  3. byteArrayToString(byte[] a)
  4. bytetoString(byte[] b)
  5. hexToString(byte[] ids)
  6. toString(byte[] ba, int offset, int length)
  7. byteToString(byte[] str)
  8. toString(byte[] buffer)
  9. toString(final byte[] bytes)