Here you can find the source of bytesToHex(byte[] b)
public static String bytesToHex(byte[] b)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { private static final String HEX = "0123456789ABCDEF"; public static String bytesToHex(byte[] b) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < b.length; i++) { sb.append(byteToHex(b[i])).append(" "); }//from w w w . j a va 2 s .co m return sb.toString(); } public static String byteToHex(byte b) { int high = (b & 0xF0) >> 4; int low = (b & 0x0F); return "" + HEX.charAt(high) + HEX.charAt(low); } }