Java Hex Calculate toHexadecimal(final byte[] array)

Here you can find the source of toHexadecimal(final byte[] array)

Description

Convert a byte array to hexadecimal representation

License

Open Source License

Parameter

Parameter Description
array Array to convert

Return

Hexadecimal representation

Declaration

public static String toHexadecimal(final byte[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   ww  w  .  j a  v a  2  s  .  com
     * Convert a byte array to hexadecimal representation
     * 
     * @param array
     *           Array to convert
     * @return Hexadecimal representation
     */
    public static String toHexadecimal(final byte[] array) {
        final int length = array.length;
        final char[] chars = new char[length * 2];

        int indexWrite = 0;
        int b;

        for (int indexRead = 0; indexRead < length; indexRead++) {
            b = array[indexRead] & 0xFF;

            chars[indexWrite++] = Integer.toHexString((b >> 4) & 0xF).charAt(0);
            chars[indexWrite++] = Integer.toHexString(b & 0xF).charAt(0);
        }

        return new String(chars);
    }
}

Related

  1. toHexa(byte[] bb)
  2. toHexAddress(long address)
  3. toHexaDecimal(byte[] bytesToConvert)
  4. toHexadecimal(byte[] digest)
  5. toHexadecimal(byte[] digest)
  6. toHexadecimal(final byte[] in)
  7. toHexadecimal(final byte[] message)
  8. toHexadecimealString(byte[] data, int length, boolean uppercase)
  9. toHexArray(byte[] binary)