Java Byte Array to Hex String bytesToHexString(byte[] bytes)

Here you can find the source of bytesToHexString(byte[] bytes)

Description

The fastest method to convert a byte array to hex string.

License

Apache License

Parameter

Parameter Description
bytes a parameter

Declaration

public static final String bytesToHexString(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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' };

    /**//from www.j a v a 2  s.  c o  m
     * The fastest method to convert a byte array to hex string.
     * @param bytes
     * @return
     */
    public static final String bytesToHexString(byte[] bytes) {
        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_CHARS[v / 16];
            hexChars[j * 2 + 1] = HEX_CHARS[v % 16];
        }
        return new String(hexChars);
    }
}

Related

  1. bytesToHexString(byte[] bytes)
  2. bytesToHexString(byte[] bytes)
  3. bytesToHexString(byte[] bytes)
  4. bytesToHexString(byte[] bytes)
  5. bytesToHexString(byte[] bytes)
  6. bytesToHexString(byte[] bytes)
  7. bytesToHexString(byte[] data)
  8. bytesToHexString(byte[] data)
  9. bytesToHexString(byte[] data, int fromIndex, int toIndex)