Here you can find the source of bytesToHex(byte[] buf)
public static String bytesToHex(byte[] buf)
//package com.java2s; public class Main { public static String bytesToHex(byte[] buf) { final StringBuilder b = new StringBuilder(buf.length * 2); for (int i = 0; i < buf.length; i++) { final int cell = (int) (buf[i] & 0xFF); if (cell < 16) { b.append("0"); }/* w ww . ja va 2 s. c o m*/ b.append(Integer.toString(cell, 16)); } return b.toString(); } }