Here you can find the source of toHexString(byte[] input)
Parameter | Description |
---|---|
input | the byte array to be converted |
public static String toHexString(byte[] input)
//package com.java2s; public class Main { private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /**/* w w w . ja v a 2 s.co m*/ * Convert a byte array to the corresponding hexstring. * * @param input the byte array to be converted * @return the corresponding hexstring */ public static String toHexString(byte[] input) { String result = ""; for (int i = 0; i < input.length; i++) { result += HEX_CHARS[(input[i] >>> 4) & 0x0f]; result += HEX_CHARS[(input[i]) & 0x0f]; } return result; } /** * Convert a byte array to the corresponding hex string. * * @param input the byte array to be converted * @param prefix the prefix to put at the beginning of the hex string * @param seperator a separator string * @return the corresponding hex string */ public static String toHexString(byte[] input, String prefix, String seperator) { String result = new String(prefix); for (int i = 0; i < input.length; i++) { result += HEX_CHARS[(input[i] >>> 4) & 0x0f]; result += HEX_CHARS[(input[i]) & 0x0f]; if (i < input.length - 1) { result += seperator; } } return result; } }