Converts a byte array to its hexadecimal representation in String form - Android java.lang

Android examples for java.lang:Byte Array

Description

Converts a byte array to its hexadecimal representation in String form

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

public class Main{

    /**//ww w.ja v a  2s.  c o m
     * Converts a byte array to its hexadecimal representation in String form. Useful for debugging
     * @param data      byte[] of data to convert
     * @return          hex of input
     */
    public static String bin2hex(byte[] data) {
        return String.format("%0" + (data.length * 2) + "X",
                new BigInteger(1, data));
    }

}

Related Tutorials