Java Hex Format formatHexBytes(byte[] raw)

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

Description

Format a raw array of binary bytes as a hexadecimal string.

License

Open Source License

Parameter

Parameter Description
raw a parameter

Declaration

public static String formatHexBytes(byte[] raw) 

Method Source Code

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

public class Main {
    /**/* w  ww. j av a 2 s. c o m*/
     * Format a raw array of binary bytes as a hexadecimal string.
     *
     * @param raw
     * @return
     */
    public static String formatHexBytes(byte[] raw) {
        StringBuffer buffer;
        final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        int i;
        int value;

        buffer = new StringBuffer(raw.length * 2);
        for (i = 0; i < raw.length; i++) {
            value = raw[i];
            buffer.append(hexDigits[(value >> 4) & 0x0F]);
            buffer.append(hexDigits[value & 0x0F]);
        }
        return buffer.toString();
    }
}

Related

  1. formatGuidToDashedNotation(String hexValue)
  2. formatHEX(byte[] btValue, int iOffset, int iLength)
  3. formatHex(double theG)
  4. formatHex(int value, int width)
  5. formatHex(Integer input)
  6. formatHexInt(final StringBuilder dst, final int p, int w)
  7. formatHexReversed(String original, int length)
  8. formatHexStr(int width, String hexStr)
  9. formatHexString(final String input, final int charsPerLine)