Here you can find the source of bytes2HexStr(byte[] bytes)
public static String bytes2HexStr(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String bytes2HexStr(byte[] bytes) { if ((bytes == null) || (bytes.length == 0)) { return null; }//from w w w .ja v a2 s . co m char[] chars = new char[bytes.length * 2]; for (int i = 0; i < bytes.length; i++) { byte b = bytes[i]; chars[(i * 2 + 1)] = DIGITS[(b & 0xF)]; b = (byte) (b >>> 4); chars[(i * 2)] = DIGITS[(b & 0xF)]; } return new String(chars); } }