Here you can find the source of toHexString(byte[] bytes)
public static String toHexString(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { public static String toHexString(byte[] bytes) { if (bytes != null) { return toHexString(bytes, 0, bytes.length); } else {/*from w w w .j a v a 2 s. c o m*/ return null; } } public static String toHexString(byte[] bytes, int offset, int count) { if (bytes != null) { StringBuffer sb = new StringBuffer(count * 2); for (int i = offset; i < offset + count; ++i) { int c = bytes[i] & 0xFF; if (c < 16) { sb.append('0'); } sb.append(Integer.toHexString(c)); } return sb.toString(); } else { return null; } } }