Java Hex Calculate toHexChars(byte[] bytes)

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

Description

Converts the given byte array to a hex character array.

License

Apache License

Declaration

public static char[] toHexChars(byte[] bytes) 

Method Source Code

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

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

    /** Converts the given byte array to a hex character array. */
    public static char[] toHexChars(byte[] bytes) {
        char[] hex = new char[bytes.length * 2];
        for (int i = 0, j = 0; i < bytes.length; i++) {
            hex[j++] = HEX[(bytes[i] >> 4) & 0xF];
            hex[j++] = HEX[bytes[i] & 0xF];
        }//from   w  ww. j  ava2s  . c  o  m
        return hex;
    }
}

Related

  1. toHexChar(int paramInt)
  2. toHexChar(int value)
  3. toHexCharArray(byte[] input)
  4. toHexCharFromBin(final String bin)
  5. toHexChars(byte[] bs)
  6. toHexChars(final int b)
  7. toHexDec(byte[] bytes)
  8. toHexDigit(char ch)
  9. toHexDigit(char ch, int index)