Here you can find the source of toHexString(byte a)
public static final String toHexString(byte a)
//package com.java2s; //License from project: GNU General Public License public class Main { /** The hexadecimal digits "0" through "f". */ private static char[] NIBBLE = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', }; public static final String toHexString(byte a) { StringBuffer sb = new StringBuffer(2); sb.append(NIBBLE[(a >>> 4) & 0xf]); sb.append(NIBBLE[a & 0xf]);/* w w w . j av a2s. c o m*/ return sb.toString(); } /** * Convert a byte array to a string of hexadecimal digits. */ public static final String toHexString(byte[] buf) { StringBuffer sb = new StringBuffer(buf.length * 2); for (int i = 0; i < buf.length; i++) { sb.append(NIBBLE[(buf[i] >>> 4) & 15]); sb.append(NIBBLE[buf[i] & 15]); } return sb.toString(); } }