Here you can find the source of toHexString(byte[] buf, int offset, int len)
public static String toHexString(byte[] buf, int offset, int len)
//package com.java2s; //License from project: Open Source License public class Main { public static char hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String toHexString(byte[] buf, int offset, int len) { if (buf == null) return "null"; StringBuilder b = new StringBuilder(); for (int i = offset, j = 0; j < len && i < buf.length; i++, j++) { int idx0 = (buf[i] & 0xff) >> 4; int idx1 = buf[i] & 0xf; b.append(hexChars[idx0]);//from w ww .j a v a 2 s . c o m b.append(hexChars[idx1]); } return b.toString(); } }