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 result = new StringBuffer(3); result.append(Integer.toString((b & 0xF0) >> 4, 16)); result.append(Integer.toString(b & 0x0F, 16)); return result.toString(); }/*from ww w . j av a2s . co m*/ public static String toHexString(byte[] bytes) { if (bytes == null) { return null; } StringBuffer result = new StringBuffer(); for (byte b : bytes) { result.append(Integer.toString((b & 0xF0) >> 4, 16)); result.append(Integer.toString(b & 0x0F, 16)); } return result.toString(); } public static String toHexString(byte[] bytes, int offset, int length) { if (bytes == null) { return null; } StringBuffer result = new StringBuffer(); for (int i = offset; i < offset + length; i++) { result.append(Integer.toString((bytes[i] & 0xF0) >> 4, 16)); result.append(Integer.toString(bytes[i] & 0x0F, 16)); } return result.toString(); } }