Here you can find the source of bytesToHex(byte[] bytes)
public static String bytesToHex(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); /**// ww w . ja v a 2 s .c om * This method converts an array of bytes to a hex string. */ public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 3]; for (int index = 0; index < bytes.length; index++) { int v = bytes[index] & 0xFF; hexChars[index * 3] = hexArray[v >>> 4]; hexChars[index * 3 + 1] = hexArray[v & 0x0F]; hexChars[index * 3 + 2] = ' '; } return new String(hexChars); } }