Android Byte Array to Int Convert bytesToInt(byte[] bytes)

Here you can find the source of bytesToInt(byte[] bytes)

Description

Converts a byte[] of unsigned bytes in big-endian order to an int.

License

Open Source License

Parameter

Parameter Description
bytes - A byte[] containing the bytes to convert.

Return

An int containing the equivalent signed value of the given bytes.

Declaration

public static int bytesToInt(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w  w  w. j  a  v  a 2s . com*/
     * Converts a byte[] of unsigned bytes in big-endian order to an int. 
     * 
     * @param bytes - A byte[] containing the bytes to convert.
     * 
     * @return An int containing the equivalent signed value of the given bytes.
     */
    public static int bytesToInt(byte[] bytes) {
        int i = 0;
        i |= (bytes[0] & 0xFF) << 24;
        i |= (bytes[1] & 0xFF) << 16;
        i |= (bytes[2] & 0xFF) << 8;
        i |= (bytes[3] & 0xFF);
        return i;
    }
}

Related

  1. byteArrayToInt(byte[] b)
  2. byteArrayToInt(byte[] bytes)
  3. bytes2Int(byte[] data)
  4. bytesToInt(byte[] b)
  5. bytesToInt(byte[] bytes)
  6. bytesToInt(byte[] in)
  7. bytesLE2int(byte[] b, int off)
  8. bytesLE2ints(byte[] b)
  9. byteToUint(byte b)