Convert byte Array To Hex String using String.format("%02x", b & 0xff) - Android java.lang

Android examples for java.lang:Hex

Description

Convert byte Array To Hex String using String.format("%02x", b & 0xff)

Demo Code

public class Main{

    @UsedForTesting/*  w ww  .j  a  va 2 s  .co  m*/
    public static String byteArrayToHexString(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return "";
        }
        final StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            sb.append(String.format("%02x", b & 0xff));
        }
        return sb.toString();
    }

}

Related Tutorials