Here you can find the source of toString(byte[] ba, int offset, int length)
public static final String toString(byte[] ba, int offset, int length)
//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); } }