Here you can find the source of toHexString(byte b)
public static String toHexString(byte b)
//package com.java2s; //License from project: Apache License public class Main { public static String toHexString(byte b) { return toHexString(new byte[] { b }, 0, 1); }/*from w w w. j a v a 2s .co m*/ public static String toHexString(byte[] b, int offset, int length) { StringBuilder buf = new StringBuilder(); for (int i = offset; i < offset + 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); } return buf.toString(); } public static String toString(byte[] bytes, int base) { StringBuilder buf = new StringBuilder(); for (byte b : bytes) { 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); } return buf.toString(); } }