convert byte array to int - Android java.lang

Android examples for java.lang:array convert

Description

convert byte array to int

Demo Code

public class Main{

    public static int byteArray2Int(byte[] array) {
        int reuslt = 0;
        byte loop;
        for (int i = 0; i < 4; i++) {
            loop = array[i];//  w  w w .ja va  2s  .co m
            int offset = array.length - i - 1;
            reuslt += (loop & 0xFF) << (8 * offset);
        }
        return reuslt;
    }

}

Related Tutorials