Here you can find the source of toHex(byte bytes[])
public static String toHex(byte bytes[])
//package com.java2s; //License from project: Open Source License public class Main { private static final String CHARS = "0123456789ABCDEF"; public static String toHex(int d) { int r = d % 16; String c = toChar(r);// ww w . ja v a2 s .com int diff = d - r; if (diff == 0) { return c; } else { int next = diff / 16; return toHex(next) + c; } } public static String toHex(byte bytes[]) { StringBuffer buf = new StringBuffer(bytes.length * 2); int i; for (i = 0; i < bytes.length; i++) { if ((bytes[i] & 0xff) < 0x10) { buf.append("0"); } buf.append(Long.toString(bytes[i] & 0xff, 16)); } return buf.toString(); } private static String toChar(int c) { int pos = Math.abs(c); return String.valueOf(CHARS.charAt(pos)); } }