Here you can find the source of toHexString(byte[] bytes)
Parameter | Description |
---|---|
bytes | The byte array |
public static String toHexString(byte[] bytes)
//package com.java2s; public class Main { final static char[] HEX_DIGIT = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /**//from w w w .ja va2 s .c o m * Converts a byte array to a hexadecimal ASCII string. * The string will be in upper case and does not start with '0x'. * This method is the reverse of <code>toBytes</code>. * * @param bytes The byte array * @return The string representing the byte array * @see #toBytes(String) */ public static String toHexString(byte[] bytes) { String str = ""; if (bytes != null) { int len = bytes.length; for (int i = 0; i < len; i++) { str += toHex(bytes[i]); } } return str; } /** * Converts one int to a hexadecimal ASCII string. * * @param val The integer * @return The hex string */ public static String toHex(int val) { int val1, val2; val1 = (val >> 4) & 0x0F; val2 = (val & 0x0F); return ("" + HEX_DIGIT[val1] + HEX_DIGIT[val2]); } }