Android Byte Array to Int Convert byteArrayToInt(byte[] b)

Here you can find the source of byteArrayToInt(byte[] b)

Description

Converts a 4 byte array to an int.

Parameter

Parameter Description
b byte array to convert.

Return

int constructed from the passed byte[].

Declaration

public static int byteArrayToInt(byte[] b) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w  w w.  j  a  va  2  s .c om*/
     * Converts a 4 byte array to an int.
     *
     * @param b byte array to convert.
     * @return int constructed from the passed byte[].
     */
    public static int byteArrayToInt(byte[] b) {
        int value = 0;
        for (int i = 0; i < 4; i++) {
            int shift = (4 - 1 - i) * 8;
            value += (b[i] & 0xFF) << shift;
        }
        return value;
    }
}

Related

  1. byteArray2Int3(byte[] b)
  2. byte2Int(byte b)
  3. byte2Integer(byte bin)
  4. byte2Integer(byte[] bin)
  5. byteArrayToInt(byte[] b)
  6. byteArrayToInt(byte[] bytes)
  7. bytes2Int(byte[] data)
  8. bytesToInt(byte[] b)
  9. bytesToInt(byte[] bytes)