Here you can find the source of bytesToHex(byte[] bytes)
Parameter | Description |
---|---|
bytes | the array to convert into hexadecimal string |
public static String bytesToHex(byte[] bytes)
//package com.java2s; public class Main { /**// w ww .j a va 2 s .co m * Convert an array of arbitrary bytes into a String of hexadecimal number-pairs with each pair representing on byte * of the array. * * @param bytes the array to convert into hexadecimal string * @return the String containing the hexadecimal representation of the array */ public static String bytesToHex(byte[] bytes) { final char[] hexArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; char[] hexChars = new char[bytes.length << 1]; for (int i = 0; i < bytes.length; i++) { int value = bytes[i] & 0xFF; int baseIndex = i << 1; hexChars[baseIndex] = hexArray[value >>> 4]; hexChars[baseIndex + 1] = hexArray[value & 0x0F]; } return new String(hexChars); } }