Here you can find the source of toHexString(final byte[] data)
Parameter | Description |
---|---|
data | data to be converted |
public static String toHexString(final byte[] data)
//package com.java2s; //License from project: Apache License public class Main { /** Digits used in the hexadecimal representation. */ public static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /**// w w w . j a va2 s . co m * Converts the specified data to hex string. * * @param data data to be converted * * @return the specified data converted to hex string * * @see #toHexString(byte[], int, int) */ public static String toHexString(final byte[] data) { return toHexString(data, 0, data.length); } /** * Converts the specified data to hex string. * * @param data data to be converted * @param offset offset of the first byte to be convert * @param length number of bytes to be converted * * @return the specified data converted to hex string * * @see #toHexString(byte[]) */ public static String toHexString(final byte[] data, int offset, int length) { final StringBuilder hexBuilder = new StringBuilder(length * 2); for (length += offset; offset < length; offset++) { final byte b = data[offset]; hexBuilder.append(HEX_DIGITS[(b & 0xff) >> 4]).append(HEX_DIGITS[b & 0x0f]); } return hexBuilder.toString(); } }