Convert byte array to Hex String - Android java.lang

Android examples for java.lang:Hex

Description

Convert byte array to Hex String

Demo Code


//package com.java2s;

public class Main {

    private static String byte2hex(byte[] b) {
        StringBuilder hs = new StringBuilder();
        String stmp;//from w  ww. j av  a2  s  . c o  m
        for (int n = 0; b != null && n < b.length; n++) {
            stmp = Integer.toHexString(b[n] & 0XFF);
            if (stmp.length() == 1)
                hs.append('0');
            hs.append(stmp);
        }
        return hs.toString().toUpperCase();
    }
}

Related Tutorials