Here you can find the source of bytesToHexString(byte[] buf)
public static String bytesToHexString(byte[] buf)
//package com.java2s; //License from project: Apache License public class Main { public static String bytesToHexString(byte[] buf) { final String decimals = "0123456789ABCDEF"; if (buf == null) return null; char[] r = new char[buf.length * 2]; for (int i = 0; i < buf.length; ++i) { r[i * 2] = decimals.charAt((buf[i] & 0xf0) >> 4); r[i * 2 + 1] = decimals.charAt(buf[i] & 0x0f); }//from w w w.ja v a 2s .c om return new String(r); } }