Here you can find the source of binaryToHex(byte[] data)
public static String binaryToHex(byte[] data)
//package com.java2s; //License from project: Open Source License public class Main { private static final char[] HexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', }; public static String binaryToHex(byte[] data) { return binaryToHex(data, 0, data.length); }//from w w w .ja v a 2s . c o m /** * Convert a string of binary bytes to the equivalent hexadecimal string. * The resulting String will have two characters for every byte in the * input. */ public static String binaryToHex(byte[] data, int offset, int length) { assert offset < data.length && offset >= 0 : offset + ", " + data.length; int end = offset + length; assert end <= data.length && end >= 0 : offset + ", " + length + ", " + data.length; char[] chars = new char[length * 2]; int j = 0; for (int i = offset; i < end; i++) { int b = data[i]; chars[j++] = hexDigit(b >>> 4 & 0xF); chars[j++] = hexDigit(b & 0xF); } return new String(chars); } public static char hexDigit(int i) { return HexDigits[i]; } }