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 { public static String toHex(byte[] bytes) { return toHex(bytes, 0, bytes.length); }/* w w w. jav a 2s . c om*/ public static String toHex(byte[] bytes, int offset, int length) { StringBuilder sb = new StringBuilder(); for (int i = offset; i < offset + length; i++) { String s = Integer.toHexString(bytes[i] & 0xff); if (s.length() == 1) { sb.append('0'); } sb.append(s); } return sb.toString(); } public static String toHex(byte b) { String s = Integer.toHexString(b & 0xff); if (s.length() == 1) { return "0" + s; } return s; } }