Convert byte array to String by size - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

Convert byte array to String by size

Demo Code


//package com.java2s;

public class Main {
    public static String toString(byte[] bytes, int size) {
        String ss = "";
        for (int i = 0; i < size; i++) {
            ss += toHex(bytes[i]);/*  w  w  w.  j  ava  2  s . c  o m*/
            //+" ";
        }
        return ss;
    }

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

Related Tutorials