Android Hex String Create toHex(byte[] data)

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

Description

to Hex

Declaration

static String toHex(byte[] data) 

Method Source Code

//package com.java2s;
import java.util.Formatter;

public class Main {
    static String toHex(byte[] data) {
        if (data == null || data.length == 0)
            return null;

        StringBuilder stringBuilder = new StringBuilder(data.length * 2);

        Formatter formatter = null;

        try {//from   w w  w  . j a v a2  s.c  om
            formatter = new Formatter(stringBuilder);

            for (byte b : data) {
                formatter.format("%02x", b);
            }

            return "0x" + stringBuilder.toString();
        } finally {
            if (formatter != null)
                formatter.close();
        }
    }
}

Related

  1. toHex(String str)
  2. toHex(String txt)
  3. toHex(byte b)
  4. toHex(byte input[])
  5. toHex(byte[] bytes)
  6. toHex(int address)
  7. toHexByte(String str, int offset, int length)
  8. toHexChar(int i)
  9. toHexDigits(byte theByte)