Here you can find the source of toHexString(byte[] bytes, int numBytes)
public static String toHexString(byte[] bytes, int numBytes)
//package com.java2s; public class Main { public static String toHexString(byte[] bytes) { return toHexString(bytes, bytes.length); }//from w w w . jav a2s. c om 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(); } }