Here you can find the source of toHexString(byte[] bytes)
Parameter | Description |
---|---|
bytes | the array of bytes |
public static String toHexString(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { private static char[] HEXES = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /**// w w w . j a v a 2s . co m * Converts an array of bytes to an Hexadecimal String * * @param bytes * the array of bytes * @return the Hexadecimal String */ public static String toHexString(byte[] bytes) { StringBuffer stringBuffer = new StringBuffer(3 * bytes.length + 2); for (int i = 0; i < bytes.length; i++) { int c = bytes[i]; if (c < 0) { c += 256; } stringBuffer.append(HEXES[c / 16]); stringBuffer.append(HEXES[c % 16]); } return stringBuffer.toString(); } }