Here you can find the source of toHexString(byte[] bytes)
public static String toHexString(byte[] bytes)
//package com.java2s; public class Main { public static String toHexString(byte[] bytes) { return toHexString(bytes, bytes.length); }//from ww w .ja v a 2 s . c o m public static String toHexString(byte[] bytes, int numBytes) { if (bytes == null) return ""; if (bytes.length == 0) return ""; StringBuffer result = new StringBuffer(); for (int i = 0; i < Math.min(numBytes, bytes.length); i++) { String h = Integer.toHexString(0xFF & bytes[i]); if (h.length() < 2) result.append('0'); result.append(h); } return result.toString(); } }