Here you can find the source of toHexString(final byte[] buffer)
Parameter | Description |
---|---|
buffer | the byte buffer |
public static String toHexString(final byte[] buffer)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w .j a v a 2 s . c om * Number of bits on a nibble. */ public static final int BITS_SIZE_OF_NIBBLE = 4; /** * The mask for the low nibble of a byte. */ public static final int INT_BYTE_LOW_NIBBLE_MASK = 0x0000000F; /** * Table of Hex digits. */ private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * Converts an array of bytes into an hex string. * * @param buffer the byte buffer * @return a string with pairs of hex digits corresponding to the byte buffer */ public static String toHexString(final byte[] buffer) { final char[] charBuffer = new char[buffer.length * 2]; for (int i = 0; i < buffer.length; ++i) { charBuffer[i * 2] = HEX_DIGITS[(buffer[i] >> BITS_SIZE_OF_NIBBLE) & INT_BYTE_LOW_NIBBLE_MASK]; charBuffer[i * 2 + 1] = HEX_DIGITS[buffer[i] & INT_BYTE_LOW_NIBBLE_MASK]; } return new String(charBuffer); } }