Here you can find the source of toHexString(byte[] bytes)
public static String toHexString(byte[] bytes)
//package com.java2s; //License from project: Mozilla Public License public class Main { private static char[] HEX_CHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String toHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { sb.append(HEX_CHARS[bytes[i] >> 4 & 0x0f]); sb.append(HEX_CHARS[bytes[i] & 0x0f]); }/*from w w w.j a v a 2 s .co m*/ return sb.toString(); } public static String toString(byte b) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 8; i++) { sb.append(((b & 0x80) == 0x80) ? "1" : "0"); b = (byte) (b << 1); } return sb.toString(); } }