Here you can find the source of toHex(byte[] data)
Parameter | Description |
---|---|
data | a parameter |
public static String toHex(byte[] data)
//package com.java2s; public class Main { /**//from w w w . j a v a 2 s . c om * Convert data to a string of hex-digits. * * @param data * @return */ public static String toHex(byte[] data) { StringBuilder sb = new StringBuilder(); for (byte b : data) { sb.append(nibbleToHex(b >>> 4)); sb.append(nibbleToHex(b)); } return sb.toString(); } /** * Get the hex-digit representation of a value. Only the first 4 bits of * the value is considered. * * @param value * @return */ public static char nibbleToHex(int value) { value &= 0xf; return (char) (value > 9 ? 'a' + (value - 10) : '0' + value); } }