Java Hex Calculate toHexString(final byte[] bytes)

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

Description

Convert the unsigned byte array to a hexadecimal string.

License

Open Source License

Parameter

Parameter Description
bytes the unsigned byte array to be converted

Return

the hexadecimal string

Declaration

public static String toHexString(final byte[] bytes) 

Method Source Code

//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);
    }
}

Related

  1. toHexString(final byte[] b)
  2. toHexString(final byte[] bs)
  3. toHexString(final byte[] bs, final char[] myDigits)
  4. toHexString(final byte[] buffer)
  5. toHexString(final byte[] bytes)
  6. toHexString(final byte[] bytes)
  7. toHexString(final byte[] bytes)
  8. toHexString(final byte[] bytes)
  9. toHexString(final byte[] data)