Here you can find the source of toHexString(byte value)
public static String toHexString(byte value)
//package com.java2s; //License from project: Apache License public class Main { public static String toHexString(byte value) { StringBuilder builder = new StringBuilder(); String hex = Integer.toHexString(value & 0xff); if (hex.length() < 2) { builder.append("0"); }//from ww w.ja v a 2 s .c om builder.append(hex); return builder.toString(); } public static String toHexString(short value) { StringBuilder builder = new StringBuilder(); String hex = Integer.toHexString(value & 0xffff); if (hex.length() < 4) { builder.append("000".substring(0, 4 - hex.length())); } builder.append(hex); return builder.toString(); } }