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 { private static final char[] hexChars = "0123456789ABCDEF".toCharArray(); public static String toHex(byte[] bytes) { return toHex(bytes, 0, bytes.length); }// www . j a v a2 s .co m public static String toHex(byte[] bytes, int offset, int length) { StringBuffer sb = new StringBuffer(); if (bytes == null) return " null"; if (offset >= length) return "invalid offset/length"; for (int i = offset; i < (length - offset); i++) { sb.append(toHex(bytes[i])); } return sb.toString(); } public static String toHex(byte val) { byte[] buff = new byte[2]; buff[0] = (byte) hexChars[(val & 0xf0) >> 4]; buff[1] = (byte) hexChars[val & 0xf]; return new String(buff); } }