Java Byte Array to Hex bytesToHex(byte[] raw)

Here you can find the source of bytesToHex(byte[] raw)

Description

bytes To Hex

License

Open Source License

Declaration

public static char[] bytesToHex(byte[] raw) 

Method Source Code

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

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

    public static char[] bytesToHex(byte[] raw) {
        int length = raw.length;
        char[] hex = new char[length * 2];
        for (int i = 0; i < length; i++) {
            int value = (raw[i] + 256) % 256;
            int highIndex = value >> 4;
            int lowIndex = value & 0x0f;
            hex[i * 2 + 0] = kDigits[highIndex];
            hex[i * 2 + 1] = kDigits[lowIndex];
        }/*from   w w w. j  a v a 2s  .com*/
        return hex;
    }
}

Related

  1. bytesToHex(byte[] data, char[] chars)
  2. bytesToHex(byte[] data, int m, int n)
  3. bytesToHex(byte[] digest)
  4. bytesToHex(byte[] in)
  5. bytesToHex(byte[] raw)
  6. bytesToHex(byte[] raw)
  7. bytesToHex(final byte[] b)
  8. bytesToHex(final byte[] bytes)
  9. bytesToHex(final byte[] bytes)