Android Byte Array to Hex Convert toHexString(byte[] data, int offset, int length)

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

Description

to Hex String

Declaration

private static String toHexString(byte[] data, int offset, int length) 

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' };

    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]);/*from www  .j ava  2 s .c  o  m*/
        }

        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)
  2. toHexString(byte[] bytes)
  3. toHexString(byte[] bytes, int numBytes)
  4. toHexString(byte[] bytes, int offset, int length)
  5. toHexString(byte[] data)
  6. toHexStringArray(byte[] data, int offset, int length)
  7. convertToHexString(byte[] input)
  8. dumpHex(byte[] bytes)
  9. getBinaryStrFromByteArr(byte[] bArr)