Android Byte Array to Hex Convert convertToHex(byte[] data)

Here you can find the source of convertToHex(byte[] data)

Description

convert To Hex

Declaration

private static String convertToHex(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {
    private static String convertToHex(byte[] data) {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            int halfbyte = (data[i] >>> 4) & 0x0F;
            int two_halfs = 0;
            do {/*from w w w . j av  a 2s.  c  om*/
                if ((0 <= halfbyte) && (halfbyte <= 9))
                    buf.append((char) ('0' + halfbyte));
                else
                    buf.append((char) ('A' + (halfbyte - 10)));
                halfbyte = data[i] & 0x0F;
            } while (two_halfs++ < 1);
        }
        return buf.toString();
    }
}

Related

  1. toHexString(byte[] bytes)
  2. toHexString(byte[] bytes, int offset, int length)
  3. toHexString(byte[] keyData)
  4. toHexStringArray(byte[] bytes)
  5. convertToHex(byte[] data)
  6. convertToHex(byte[] data)
  7. convertToHexString(byte[] b)
  8. encodeHex(byte[] data)
  9. encodeHex(byte[] data)