Here you can find the source of toHex(final byte[] data)
Parameter | Description |
---|---|
data | the bytes to be converted. |
public static String toHex(final byte[] data)
//package com.java2s; public class Main { /**//from ww w . jav a 2 s. c o m * Return length many bytes of the passed in byte array as a hex string. * * @param data the bytes to be converted. * @param length the number of bytes in the data block to be converted. * @return a hex representation of length bytes of data. */ public static String toHex(final byte[] data, final int length) { final StringBuffer buf = new StringBuffer(); final String digits = "0123456789abcdef"; for (int i = 0; i != length; i++) { final int variName = data[i] & 0xff;//NOCHECKSTYLE '0xff' buf.append(digits.charAt(variName >> 4));//NOCHECKSTYLE '4' buf.append(digits.charAt(variName & 0xf));//NOCHECKSTYLE '0xf' } return buf.toString(); } /** * Return the passed in byte array as a hex string. * * @param data the bytes to be converted. * @return a hex representation of data. */ public static String toHex(final byte[] data) { return toHex(data, data.length); } }