Here you can find the source of toHex(byte[] bytes)
public static String toHex(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { /** A table of hex digits */ private static final char[] hexDigit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /**/* www.jav a 2 s . co m*/ * Convert a nibble to a hex character * @param nibble the nibble to convert. */ public static char toHex(int nibble) { return hexDigit[(nibble & 0xF)]; } public static String toHex(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length * 2); for (byte b : bytes) { sb.append(toHex(b >>> 4)); sb.append(toHex(b)); } return sb.toString(); } }