Here you can find the source of formatAsHex(byte[] bytes)
public static String formatAsHex(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { protected static final char[] hexDigits = "0123456789ABCDEF" .toCharArray();/*from w ww.ja v a2 s .c om*/ /** * Formats the specified byte array as a hex string. */ public static String formatAsHex(byte[] bytes) { if (bytes == null || bytes.length == 0) return ""; char[] chars = new char[bytes.length * 2]; for (int i = 0; i < bytes.length; i++) { int b = bytes[i] & 0xff; chars[i * 2] = hexDigits[b >>> 4]; chars[i * 2 + 1] = hexDigits[b & 0x0f]; } return new String(chars); } }