Android Byte Array to Hex Convert byteArrayToHexString(final byte[] array)

Here you can find the source of byteArrayToHexString(final byte[] array)

Description

Gets a pretty representation of a Byte Array as a HEX String.

Parameter

Parameter Description
array the array

Return

the string

Declaration

public static String byteArrayToHexString(final byte[] array) 

Method Source Code

//package com.java2s;

public class Main {
    /** The Constant HEXES. */
    private static final String HEXES = "0123456789ABCDEF";

    /**/*www .  ja v a  2s  .  com*/
     * Gets a pretty representation of a Byte Array as a HEX String.
     *
     * Sample output: [01, 30, FF, AA]
     *
     * @param array the array
     * @return the string
     */
    public static String byteArrayToHexString(final byte[] array) {
        final StringBuffer sb = new StringBuffer();
        boolean firstEntry = true;
        sb.append('[');

        for (final byte b : array) {
            if (!firstEntry) {
                sb.append(", ");
            }
            sb.append(HEXES.charAt((b & 0xF0) >> 4));
            sb.append(HEXES.charAt((b & 0x0F)));
            firstEntry = false;
        }

        sb.append(']');
        return sb.toString();
    }
}

Related

  1. byte2hex(byte[] b)
  2. byte2hex(byte[] buffer)
  3. byte2hex(byte[] buffer, int len)
  4. byte2hexWithoutSpace(byte[] buffer)
  5. byteArrayToHexString(byte[] b)
  6. byteToHexString(Byte b)
  7. byteToHexString(byte b)
  8. byteToHexString(byte value)
  9. bytesToHex(byte[] bytes)