base16 decode byte array to String - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

base16 decode byte array to String

Demo Code


//package com.book2s;

public class Main {
    public static final int BYTE_MASK = 0xff;

    public static String base16(byte[] data) {
        return byteArray2HexString(data);
    }//from   w  ww .  j  av a2s  .  c o  m

    public static String byteArray2HexString(byte[] data) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            String temp = Integer.toHexString(data[i] & BYTE_MASK);
            if (temp.length() == 1)
                temp = "0" + temp;
            sb.append(temp);
        }
        return sb.toString().toUpperCase();
    }
}

Related Tutorials