Java Hex Calculate toHexString(byte bytes[])

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

Description

Convert a collection of bytes from an MD5 hash to a string.

License

Open Source License

Parameter

Parameter Description
bytes the bytes to be converted

Return

the resulting string

Declaration

protected static String toHexString(byte bytes[]) 

Method Source Code

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

public class Main {
    protected static final char HEXCODE[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**/*w ww.j ava2  s. c o m*/
     * Convert a collection of bytes from an MD5 hash to a string.
     * @param bytes the bytes to be converted
     * @return the resulting string
     */
    protected static String toHexString(byte bytes[]) {
        char chars[] = new char[bytes.length * 2];

        for (int i = 0; i < bytes.length; ++i) {
            chars[2 * i] = HEXCODE[(bytes[i] & 0xF0) >>> 4];
            chars[2 * i + 1] = HEXCODE[bytes[i] & 0x0F];
        }
        return new String(chars);
    }
}

Related

  1. toHexString(byte buffer[])
  2. toHexString(byte buffer[])
  3. toHexString(byte bytes[])
  4. toHexString(byte bytes[])
  5. toHexString(byte bytes[])
  6. toHexString(byte bytes[])
  7. toHexString(byte bytes[])
  8. toHexString(byte data[])
  9. toHexString(byte input[])