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 twoHalves = 0;
            do {//from   w ww . j  ava 2  s.com
                if ((0 <= halfByte) && (halfByte <= 9))
                    buf.append((char) ('0' + halfByte));
                else
                    buf.append((char) ('a' + (halfByte - 10)));
                halfByte = data[i] & 0x0F;
            } while (twoHalves++ < 1);
        }
        return buf.toString();
    }
}

Related

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