Here you can find the source of toHexString(byte[] b)
public static String toHexString(byte[] b)
//package com.java2s; public class Main { public static String toHexString(byte[] b) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < b.length; i++) { int bi = 0xff & b[i]; int c = '0' + (bi / 16) % 16; if (c > '9') c = 'A' + (c - '0' - 10); buf.append((char) c); c = '0' + bi % 16; if (c > '9') c = 'a' + (c - '0' - 10); buf.append((char) c); }/*from w w w .j a v a 2 s .co m*/ return buf.toString(); } /** Append substring to StringBuffer * @param buf StringBuffer to append to * @param s String to append from * @param offset The offset of the substring * @param length The length of the substring */ public static void append(StringBuffer buf, String s, int offset, int length) { synchronized (buf) { int end = offset + length; for (int i = offset; i < end; i++) { if (i >= s.length()) break; buf.append(s.charAt(i)); } } } public static void append(StringBuffer buf, byte b, int base) { int bi = 0xff & b; int c = '0' + (bi / base) % base; if (c > '9') c = 'a' + (c - '0' - 10); buf.append((char) c); c = '0' + bi % base; if (c > '9') c = 'a' + (c - '0' - 10); buf.append((char) c); } }