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

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

Description

bytes Hex String

Declaration

public static String bytes2HexString(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {

    public static String bytes2HexString(byte[] data) {
        String ret = "";
        for (int i = 0; i < data.length; i++) {
            String hex = Integer.toHexString(data[i] & 0xFF);
            if (hex.length() == 1) {
                hex = '0' + hex;
            }//from w w w. j  a va  2  s.c  o  m
            ret += hex.toUpperCase();
        }
        return ret;
    }

    private static String toHexString(byte[] b) { // String to byte
        char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
                '9', 'A', 'B', 'C', 'D', 'E', 'F' };

        StringBuilder sb = new StringBuilder(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
            sb.append(HEX_DIGITS[b[i] & 0x0f]);
        }
        return sb.toString();
    }
}

Related

  1. toHexString(byte[] bytes)
  2. encodeHexStr(final byte[] bytes)
  3. byteArrayToHexString(byte[] b)
  4. getHexString(byte[] raw)
  5. byte2hex(byte[] b)
  6. bytes2HexString(byte[] data)
  7. toHexString(byte[] b)
  8. byteArrayToHexString(byte[] data)
  9. bytesToHexString(byte[] bArray)