Here you can find the source of toHex(byte b, String prefix)
public static String toHex(byte b, String prefix)
//package com.java2s; // it under the terms of the GNU General Public License as published by public class Main { public static final String HEX_PREFIX = "0x"; public static String toHex(byte b) { return toHex(b, HEX_PREFIX); }// w w w.j a va 2s .co m public static String toHex(byte b, String prefix) { return prefix + String.format("%02x", b); } public static String toHex(short s) { return toHex(s, HEX_PREFIX); } public static String toHex(short s, String prefix) { return prefix + String.format("%04x", s); } }