Here you can find the source of toHexString(byte value)
public static String toHexString(byte value)
//package com.java2s; public class Main { final static byte[] digits = { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' }; public static String toHexString(byte value) { return toUnsignedString(value & 0xFF, 4); }/*from www .j a v a 2s. c om*/ static String toUnsignedString(int i, int shift) { byte[] buf = new byte[] { (byte) '0', (byte) '0' }; int charPos = 2; int radix = 1 << shift; int mask = radix - 1; do { buf[--charPos] = digits[i & mask]; i >>>= shift; } while (i != 0); return new String(buf); } }