Here you can find the source of bytes2HexPP2(byte[] bytes)
public static String bytes2HexPP2(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String bytes2HexPP2(byte[] bytes) { // if(bytes[0] == 0){ // bytes = Arrays.copyOfRange(bytes, 1, bytes.length-1); // } char[] hexChars = new char[bytes.length * 3]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 3] = ' '; hexChars[j * 3 + 1] = hexArray[v >>> 4]; hexChars[j * 3 + 2] = hexArray[v & 0x0F]; }/*ww w.j a v a 2 s.c om*/ return new String(hexChars).substring(1); } }