Java Array Dump dumpHex(byte[] data, int offset, int length)

Here you can find the source of dumpHex(byte[] data, int offset, int length)

Description

Returns the RAW bytes as hexadecimal string.

License

Open Source License

Parameter

Parameter Description
data The RAW bytes.

Return

The hexadecimal string.

Declaration

public static String dumpHex(byte[] data, int offset, int length) 

Method Source Code

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

public class Main {
    private static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
            'F' };

    /**//from  w  w  w  .jav  a 2s  .  c  o  m
     * Returns the RAW bytes as hexadecimal string.
     * This method is used for debugging.
     *
     * @param data The RAW bytes.
     * @return The hexadecimal string.
     */
    public static String dumpHex(byte[] data, int offset, int length) {
        char[] hex = new char[2 * length];
        for (int i = 0; i < length; ++i) {
            final int b = data[offset + i] & 0xFF;
            hex[2 * i + 0] = HEX[b >>> 4];
            hex[2 * i + 1] = HEX[b & 0x0F];
        }

        return new String(hex);
    }

    public static String dumpHex(byte[] data) {
        return data != null ? dumpHex(data, 0, data.length) : "null";
    }

    /**
     * Returns the integer as hexadecimal string.
     *
     * @param val The integer value.
     * @param width The number of characters to dump.
     * @return The hexadecimal string.
     */
    public static String dumpHex(long val, int width) {
        char[] hex = new char[width];
        for (int i = 0; i < width; ++i) {
            final long b = (val >>> ((width - 1 - i) * 4));
            hex[i] = HEX[(int) b & 0x0F];
        }

        return new String(hex);
    }
}

Related

  1. dumpAsHex(byte[] src, int length)
  2. dumpCharCharArray(String msg, char[][] o)
  3. dumpData(byte data[])
  4. dumpFirst1024Byte(byte[] data)
  5. dumpGroups(String title, int[][] allGroups)
  6. dumpHexString(final byte[] array)
  7. dumpInt(String name, int[] src)
  8. dumpIntArray(int[] A, int n)
  9. dumpIntArray(int[] data, String label)