Here you can find the source of toHex(final byte[] data)
Parameter | Description |
---|---|
data | - Data to convert to hexadecimal |
private static String toHex(final byte[] data)
//package com.java2s; //License from project: LGPL public class Main { /**/*from w w w .jav a 2 s. c om*/ * Converts data to an hexadecimal string * * @param data * - Data to convert to hexadecimal * @return String in hexadecimal */ private static String toHex(final byte[] data) { final StringBuffer buf = new StringBuffer(); for (final byte element : data) { int halfbyte = (element >>> 4) & 0x0F; int two_halfs = 0; do { if ((0 <= halfbyte) && (halfbyte <= 9)) { buf.append((char) ('0' + halfbyte)); } else { buf.append((char) ('a' + (halfbyte - 10))); } halfbyte = element & 0x0F; } while (two_halfs++ < 1); } return buf.toString(); } }