show byte array Buffer as string - Android File Input Output

Android examples for File Input Output:Byte Array

Description

show byte array Buffer as string

Demo Code


//package com.java2s;
import android.util.Log;

public class Main {
    public static void showBuffer(String tag, byte[] bytes, int size) {
        Log.e(tag, toString(bytes, size));
    }/*  w  ww.  j a v  a2  s .com*/

    public static String toString(byte[] bytes, int size) {
        String ss = "";
        for (int i = 0; i < size; i++) {
            ss += toHex(bytes[i]);
            //+" ";
        }
        return ss;
    }

    public static String toHex(byte b) {
        return ("" + "0123456789ABCDEF".charAt(0xf & b >> 4) + "0123456789ABCDEF"
                .charAt(b & 0xf));
    }
}

Related Tutorials