Here you can find the source of bytesToHex(final byte[] bytes)
Parameter | Description |
---|---|
bytes | Bytes to convert |
public static String bytesToHex(final byte[] bytes)
//package com.java2s; /**/*from w w w . j av a 2 s . c om*/ * WS-Attacker - A Modular Web Services Penetration Testing Framework Copyright * (C) 2013 Dennis Kupser * * This program 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 2 of the License, or (at your option) any later * version. * * This program 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 * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ public class Main { /** * Valid Hex Chars. */ private final static char[] HEXCHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * Converts a byte array into its hex string representation. * * @param bytes Bytes to convert * @return Hex string of delivered byte array */ public static String bytesToHex(final byte[] bytes) { StringBuilder builder = new StringBuilder(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { // unsigned right shift of the MSBs builder.append(HEXCHARS[(bytes[i] & 0xff) >>> 4]); // handling the LSBs builder.append(HEXCHARS[bytes[i] & 0xf]); builder.append(' '); } return builder.toString(); } }