Here you can find the source of bytesToHex(byte[] data)
public static String bytesToHex(byte[] data)
//package com.java2s; //License from project: Open Source License public class Main { public static String bytesToHex(byte[] data) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < data.length; i++) { buf.append(byteToHex(data[i]).toUpperCase()); }//from w ww.j a v a2 s .c o m return (buf.toString()); } public static String byteToHex(byte data) { StringBuffer buf = new StringBuffer(); buf.append(toHexChar((data >>> 4) & 0x0F)); buf.append(toHexChar(data & 0x0F)); return buf.toString(); } public static char toHexChar(int i) { if ((0 <= i) && (i <= 9)) { return (char) ('0' + i); } else { return (char) ('a' + (i - 10)); } } }