Here you can find the source of bytesToHex(byte[] bs, int off, int length)
public static final String bytesToHex(byte[] bs, int off, int length)
//package com.java2s; //License from project: Open Source License public class Main { public static final String bytesToHex(byte[] bs, int off, int length) { StringBuffer sb = new StringBuffer(length * 2); bytesToHexAppend(bs, off, length, sb); return sb.toString(); }/*from ww w .j a v a 2 s. c o m*/ public static final String bytesToHex(byte[] bs) { return bytesToHex(bs, 0, bs.length); } public static final void bytesToHexAppend(byte[] bs, int off, int length, StringBuffer sb) { sb.ensureCapacity(sb.length() + length * 2); for (int i = off; i < (off + length) && i < bs.length; i++) { sb.append(Character.forDigit((bs[i] >>> 4) & 0xf, 16)); sb.append(Character.forDigit(bs[i] & 0xf, 16)); } } }