Here you can find the source of bufferToHex(byte bytes[])
private static String bufferToHex(byte bytes[])
//package com.java2s; public class Main { public static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; private static String bufferToHex(byte bytes[]) { return bufferToHex(bytes, 0, bytes.length); }/* ww w . j a va 2 s . com*/ private static String bufferToHex(byte[] bytes, int i, int length) { StringBuffer sb = new StringBuffer(2 * length); int k = i + length; for (int l = i; l < k; l++) { appendHexPair(bytes[l], sb); } return sb.toString(); } private static void appendHexPair(byte b, StringBuffer sb) { char c0 = hexDigits[(b & 0xf0) >> 4]; char c1 = hexDigits[b & 0x0f]; sb.append(c0); sb.append(c1); } }