Convert byte to hex - Android java.lang

Android examples for java.lang:Byte Array

Description

Convert byte to hex

Demo Code


//package com.java2s;

public class Main {

    public static String byte2hex(byte[] b) { 
        StringBuffer sb = new StringBuffer(b.length * 2);
        String tmp = "";
        for (int n = 0; n < b.length; n++) {

            tmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
            if (tmp.length() == 1) {
                sb.append("0");
            }/*ww  w .  jav a2 s  .c  o  m*/
            sb.append(tmp);
        }
        return sb.toString().toUpperCase(); 
    }
}

Related Tutorials