Here you can find the source of bytesToHexStringWithSpace(byte[] bytes)
public static String bytesToHexStringWithSpace(byte[] bytes)
//package com.java2s; /*//www .j ava2 s.c o m Copyright 2015 Rudolf Fiala This file is part of Alpheus AFP Parser. Alpheus AFP Parser is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Alpheus AFP Parser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Alpheus AFP Parser. If not, see <http://www.gnu.org/licenses/> */ public class Main { public static final char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String bytesToHexStringWithSpace(byte[] bytes) { char[] hexChars = new char[2 + ((bytes.length - 1) * 3)]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 3] = hexArray[v >>> 4]; hexChars[j * 3 + 1] = hexArray[v & 0x0F]; if (hexChars.length < (j * 3 + 2)) { hexChars[j * 3 + 2] = ' '; } } return new String(hexChars); } }