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

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

Description

Converts a byte array into a String of its hexadecimal representation.

Parameter

Parameter Description
data The array of bytes to be converted.

Return

The hexadecimal String representation of the byte array.

Declaration

public static String toHexString(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*w ww . ja  v a 2  s  .  c  om*/
     * Converts a byte array into a String of its hexadecimal representation.
     * This method should be called statically.
     * @param data The array of bytes to be converted.
     * @return The hexadecimal String representation of the byte array.
     */
    public static String toHexString(byte[] data) {
        int c;
        String res = "", s;
        for (byte aux : data) {
            c = aux & 0xff;
            s = Integer.toHexString(c);
            if (s.length() == 1)
                res += "0";
            res += s;
        }
        return res;
    }
}

Related

  1. hex2byte(byte[] b)
  2. toHex(byte[] buf)
  3. toHex(byte[] data)
  4. toHexString(byte[] b)
  5. toHexString(byte[] buf, int offset, int length)
  6. getHexString(byte[] b)
  7. getHexString(byte[] b, String splitString)
  8. toHex(byte[] b)
  9. bytesToHexString(byte[] bytes)