Here you can find the source of bufferToHexString(byte[] buffer)
Parameter | Description |
---|---|
buffer | byte buffer |
public static String bufferToHexString(byte[] buffer)
//package com.java2s; /*/* www . j a va 2 s. c om*/ * Copyright (C) 2002-2017 FlyMine * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. See the LICENSE file for more * information or http://www.gnu.org/copyleft/lesser.html. * */ public class Main { private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** * Convert a byte buffer to a hexadecimal string. * @param buffer byte buffer * @return hexadecimal string */ public static String bufferToHexString(byte[] buffer) { StringBuffer sb = new StringBuffer(buffer.length * 2); for (int i = 0; i < buffer.length; i++) { char a = HEX_CHARS[(buffer[i] & 0xF0) >> 4]; char b = HEX_CHARS[buffer[i] & 0x0F]; sb.append(a); sb.append(b); } return sb.toString(); } }