Convert byte array To Int by shifting left - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

Convert byte array To Int by shifting left

Demo Code


//package com.java2s;

public class Main {
    public static int bytesToInt(byte[] b) {
        int result = 0;
        for (int i = 0; i < 4; i++) {
            result <<= 8;//from w w w  . j  a v a  2s .c  o m

            if (i < b.length) {
                result |= (b[i] & 0xFF);
            }
        }

        return result;
    }
}

Related Tutorials