Android Byte Array to Hex Convert dumpHex(byte[] bytes)

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

Description

dump Hex

Declaration

public static String dumpHex(byte[] bytes) 

Method Source Code

//package com.java2s;

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

    public static String dumpHex(byte[] bytes) {
        return bytesToHex(bytes);
    }/* w w w .  ja  va  2  s  .  c  o m*/

    public static String bytesToHex(byte[] bytes) {
        return toHexString(bytes, 0, bytes.length);
    }

    private static String toHexString(byte[] data, int offset, int length) {
        StringBuilder s = new StringBuilder(length * 2);
        int end = offset + length;

        int high_nibble;
        int low_nibble;

        for (int i = offset; i < end; i++) {
            high_nibble = (data[i] & 0xF0) >>> 4;
            low_nibble = (data[i] & 0x0F);

            s.append(HEXS[high_nibble]);
            s.append(HEXS[low_nibble]);
        }

        return s.toString();
    }

    private static String toHexString(byte byt) {
        String result = null;

        int high_nibble;
        int low_nibble;

        high_nibble = (byt & 0xF0) >>> 4;
        low_nibble = (byt & 0x0F);

        result = "" + HEXS[high_nibble] + HEXS[low_nibble];

        return result;
    }
}

Related

  1. toHexString(byte[] bytes, int offset, int length)
  2. toHexString(byte[] data)
  3. toHexString(byte[] data, int offset, int length)
  4. toHexStringArray(byte[] data, int offset, int length)
  5. convertToHexString(byte[] input)
  6. getBinaryStrFromByteArr(byte[] bArr)
  7. toHex(byte[] buf)
  8. toHex(byte[] buf)
  9. byte2hex(byte[] b)