Here you can find the source of toHex(byte[] data)
public static String toHex(byte[] data)
//package com.java2s; /**/*from w w w . j a va 2s .com*/ * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at * * http://www.dspace.org/license/ */ public class Main { /** * Reasonably efficient Hex checksum converter * * @param data * byte array * @return hexString * checksum */ static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); public static String toHex(byte[] data) { if ((data == null) || (data.length == 0)) { return null; } char[] chars = new char[2 * data.length]; for (int i = 0; i < data.length; ++i) { chars[2 * i] = HEX_CHARS[(data[i] & 0xF0) >>> 4]; chars[2 * i + 1] = HEX_CHARS[data[i] & 0x0F]; } return new String(chars); } }