Here you can find the source of byteToHex(byte b)
private static char[] byteToHex(byte b)
//package com.java2s; //License from project: Open Source License public class Main { private static char[] byteToHex(byte b) { int unsignedByte = (int) b - Byte.MIN_VALUE; return new char[] { unsignedIntToHex((unsignedByte >> 4) & 0xf), unsignedIntToHex(unsignedByte & 0xf) }; }// w w w . ja v a2 s . c o m private static char unsignedIntToHex(int i) { if (i >= 0 && i <= 9) { return (char) (i + 48); } else if (i >= 10 && i <= 15) { return (char) (i + 87); } else { throw new IllegalArgumentException( "Invalid hex int: out of range"); } } }