Here you can find the source of toHex(byte b)
public static String toHex(byte b)
//package com.java2s; //License from project: Open Source License public class Main { public static String toHex(byte b) { b += 0x80;/*from www. j a v a 2 s .com*/ int hb = (b & 0xF0) >> 4; int lb = b & 0x0F; return toHex(hb) + toHex(lb); } public static String toHex(int half_byte) { if (half_byte > 15 || half_byte < 0) return null; if (half_byte < 10) { return String.valueOf(half_byte); } else { switch (half_byte) { case (10): return "A"; case (11): return "B"; case (12): return "C"; case (13): return "D"; case (14): return "E"; case (15): return "F"; default: return null; } } } }