Here you can find the source of toHex(byte[] inBytes)
public static String toHex(byte[] inBytes)
//package com.java2s; //License from project: Open Source License public class Main { /**// ww w .j a v a 2s . co m * toHex (String) returns the passed string in hex */ public static String toHex(String inString) { StringBuffer outString = new StringBuffer(4 * inString.length()); for (int i = 0; i < inString.length(); i++) { String hexChar = Integer.toHexString(inString.charAt(i)); // Make the number of hex chars even if (hexChar.length() % 2 == 1) outString.append("0"); outString.append(hexChar); } return outString.toString(); } /** * toHex (byte []) returns the passed byte array in hex */ public static String toHex(byte[] inBytes) { StringBuffer outString = new StringBuffer(4 * inBytes.length); for (int i = 0; i < inBytes.length; i++) { String hexChar; if (inBytes[i] < 0) hexChar = Integer.toHexString(256 + inBytes[i]); else hexChar = Integer.toHexString(inBytes[i]); // Make the number of hex chars even if (hexChar.length() % 2 == 1) outString.append("0"); outString.append(hexChar); } return outString.toString(); } }