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) { StringBuffer hexString = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(0xFF & bytes[i]); if (hex.length() == 1) { // could use a for loop, but we're only dealing with a single byte hexString.append('0'); }/*w w w . j av a 2 s.c om*/ hexString.append(hex); } return hexString.toString(); } }