Format byte array To Hex String using String.format - Android java.lang

Android examples for java.lang:Hex

Description

Format byte array To Hex String using String.format

Demo Code

import android.text.TextUtils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main{

    private static String bytesToHexString(byte[] bytes) {
        StringBuffer sb = new StringBuffer();
        for (byte b : bytes) {
            sb.append(String.format("%02x", b));
        }/*from  w ww.j  a va  2 s  .  c  o m*/
        return sb.toString();
    }

}

Related Tutorials