Android Byte Array to Hex Convert encodeHex(byte[] data)

Here you can find the source of encodeHex(byte[] data)

Description

byte[] to hex

Parameter

Parameter Description
data byte[]

Return

hex char[]

Declaration

public static String encodeHex(byte[] data) 

Method Source Code

//package com.java2s;

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

    /**//from www . j  av a 2  s. c om
     * byte[] to hex
     *
     * @param data byte[]
     * @return hex char[]
     */
    public static String encodeHex(byte[] data) {

        int l = data.length;
        char[] out = new char[l << 1];
        //two characters form the hex value.
        for (int i = 0, j = 0; i < l; i++) {
            out[j++] = DIGITS_LOWER[(0xF0 & data[i]) >>> 4];
            out[j++] = DIGITS_LOWER[0x0F & data[i]];
        }
        return new String(out);
    }
}

Related

  1. toHex(byte[] buf)
  2. toHex(byte[] buf)
  3. byte2hex(byte[] b)
  4. byte2hex(byte[] b)
  5. hexEncode(byte[] data)
  6. decodeHex(char[] data)
  7. bytesToHex(byte[] data)
  8. bytesToHexString(byte[] bytesArray)
  9. parseByte2HexStr(byte buf[])