Here you can find the source of toHexString(final byte[] bytes)
Parameter | Description |
---|---|
bytes | the unsigned byte array to be converted |
public static String toHexString(final byte[] bytes)
//package com.java2s; public class Main { static final char[] hexArray = "0123456789abcdef".toCharArray(); /**// w w w .j ava2 s. c o m * Convert the unsigned byte array to a hexadecimal string. * * @param bytes the unsigned byte array to be converted * @return the hexadecimal string */ public static String toHexString(final byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; int value; for (int index = 0; index < bytes.length; index++) { value = bytes[index] & 0xFF; hexChars[index * 2] = hexArray[value >> 4]; hexChars[index * 2 + 1] = hexArray[value & 0x0F]; } return new String(hexChars); } }