Android Array to String Convert toString(byte[] ba, int offset, int length)

Here you can find the source of toString(byte[] ba, int offset, int length)

Description

to String

Declaration

public static final String toString(byte[] ba, int offset, int length) 

Method Source Code

//package com.java2s;

public class Main {
    private static final char[] HEX_DIGITS = "0123456789ABCDEF"
            .toCharArray();//from  w w  w  . ja 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(Object[] obj)
  2. byteArrayToString(byte[] a)
  3. bytetoString(byte[] b)
  4. hexToString(byte[] ids)
  5. toString(byte[] ba)
  6. byteToString(byte[] str)
  7. toString(byte[] buffer)
  8. toString(final byte[] bytes)
  9. toString(final byte[] bytes, String charset)