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 { /** Most significant bits mask for binary operations */ public static final int MOST_SIGNIFICANT_MASK = 0xFF; /** Least significant bits mask for binary operations */ public static final int LEAST_SIGNIFICANT_MASK = 0x0F; /** {@code char[]} in which each position contains the hex value textual representation */ protected static final char[] hexArray = "0123456789ABCDEF" .toCharArray(); private static char[] byteToHex(byte b) { char[] hexChars = new char[2]; int v = b & MOST_SIGNIFICANT_MASK; hexChars[0] = hexArray[v >>> 4]; hexChars[1] = hexArray[v & LEAST_SIGNIFICANT_MASK]; return hexChars; }//from ww w .j a v a 2 s.c o m }