Java Hex Format formatAsHex(byte[] bytes)

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

Description

Formats the specified byte array as a hex string.

License

Open Source License

Declaration

public static String formatAsHex(byte[] bytes) 

Method Source Code

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

public class Main {
    protected static final char[] hexDigits = "0123456789ABCDEF"
            .toCharArray();/*from   w  ww.ja  v a2 s  .c  om*/

    /**
     * Formats the specified byte array as a hex string.
     */
    public static String formatAsHex(byte[] bytes) {
        if (bytes == null || bytes.length == 0)
            return "";
        char[] chars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            int b = bytes[i] & 0xff;
            chars[i * 2] = hexDigits[b >>> 4];
            chars[i * 2 + 1] = hexDigits[b & 0x0f];
        }
        return new String(chars);
    }
}

Related

  1. formatAddress6(int[] hexRepresentation)
  2. FormatAs2CharHexa(byte byValue)
  3. FormatAs4CharHexa(int nValue)
  4. formatAsHex(long msgId)
  5. formatAsHexUppercase(long msgId)
  6. formatAsRawHex(int bitStringLength, String hex)
  7. formatBytes2HexString(byte[] bytes, int offset, int length)