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

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

Description

bytes To Hex

Declaration

public static String bytesToHex(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 bytesToHex(byte[] bytes) {
        return toHexString(bytes, 0, bytes.length);
    }//from  w  ww  .ja  v  a  2s.  c  o  m

    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. byteArrayToHexString(byte[] b)
  2. byteArrayToHexString(final byte[] array)
  3. byteToHexString(Byte b)
  4. byteToHexString(byte b)
  5. byteToHexString(byte value)
  6. bytesToHex(byte[] bytes)
  7. bytesToHex(byte[] bytes)
  8. bytesToHexString(byte[] b)
  9. bytesToHexString(byte[] src)