Here you can find the source of toHexString(byte[] bytes)
Parameter | Description |
---|---|
bytes | the byte values to convert, cannot be <code>null</code>. |
null
.
public static String toHexString(byte[] bytes)
//package com.java2s; /**//from www .jav a2 s . c o m * Licensed under Apache License v2. See LICENSE for more information. */ public class Main { /** The hexadecimal alphabet. */ private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); /** * Creates a hexadecimal representation of all given bytes an concatenates these * hex-values to a single string. * * @param bytes the byte values to convert, cannot be <code>null</code>. * @return a hex-string of the given bytes, never <code>null</code>. */ public static String toHexString(byte[] bytes) { // based on <http://stackoverflow.com/a/9855338/229140> char[] hexChars = new char[bytes.length * 2]; int v; for (int j = 0; j < bytes.length; j++) { v = bytes[j] & 0xFF; hexChars[j * 2] = HEX_DIGITS[v >>> 4]; hexChars[j * 2 + 1] = HEX_DIGITS[v & 0x0F]; } return new String(hexChars); } }