Java Hex Calculate toHex(byte[] buffer)

Here you can find the source of toHex(byte[] buffer)

Description

Render a byte array into a string of hexadecimal numbers.

License

Open Source License

Parameter

Parameter Description
buffer containing the bytes to convert

Return

a character array of length 2 with hexadecimal digits representing the bytes.

Declaration

public static char[] toHex(byte[] buffer) 

Method Source Code

//package com.java2s;

public class Main {
    private static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f' };

    /**/*www .  j  ava 2  s.c o m*/
     * Render a byte array into a string of hexadecimal numbers.
     * @param buffer containing the bytes to convert
     * @return a character array of length 2 with hexadecimal digits representing the bytes.
     */
    public static char[] toHex(byte[] buffer) {
        char[] result = new char[buffer.length * 2];
        for (int i = 0; i < buffer.length; i++) {
            result[i << 1] = HEX[(buffer[i] & 0xF0) >>> 4];
            result[(i << 1) + 1] = HEX[buffer[i] & 0x0F];
        }
        return result;
    }
}

Related

  1. toHex(byte[] b)
  2. toHex(byte[] b)
  3. toHex(byte[] b, int off, int len, String separator)
  4. toHEX(byte[] ba)
  5. toHex(byte[] buffer)
  6. toHex(byte[] bytes)
  7. toHex(byte[] bytes)
  8. toHex(byte[] bytes)
  9. toHex(byte[] bytes)