byte Array Little Endian Int - Android File Input Output

Android examples for File Input Output:Byte Array

Description

byte Array Little Endian Int

Demo Code


//package com.book2s;

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

    public static int byteArrayLittleEndian2Int(byte[] bs) {
        if (bs.length != 4)
            throw new IllegalArgumentException();
        int res = 0;
        res |= (bs[3] & BYTE_MASK) << 24;
        res |= (bs[2] & BYTE_MASK) << 16;
        res |= (bs[1] & BYTE_MASK) << 8;
        res |= (bs[0] & BYTE_MASK);/*  w w w  .j  a v  a 2s .com*/
        return res;

    }
}

Related Tutorials