Java Integer Create toInt(byte[] input)

Here you can find the source of toInt(byte[] input)

Description

Converts a given byte array to an int .

License

BSD License

Parameter

Parameter Description
input A network byte-ordered representation of an int .

Return

The int value represented by the input array.

Declaration

public static int toInt(byte[] input) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    /**/* w w w.  jav  a  2s  .c  o  m*/
     * Converts a given byte array to an {@code int}. Bytes are expected in
     * network byte order.
     *
     * @param input A network byte-ordered representation of an {@code int}.
     * @return The {@code int} value represented by the input array.
     */
    public static int toInt(byte[] input) {
        assert input.length == 4 : "toInt(): Byte array length must be 4.";
        int output = 0;
        output = ((input[0] & 0xff) << 24) | ((input[1] & 0xff) << 16) | ((input[2] & 0xff) << 8)
                | (input[3] & 0xff);
        return output;
    }
}

Related

  1. toInt(byte[] data)
  2. toInt(byte[] data)
  3. toInt(byte[] data, int offset, int length)
  4. toInt(byte[] in)
  5. toInt(byte[] in)
  6. toInt(byte[] key)
  7. toInt(byte[] n)
  8. toInt(byte[] readBuffer, int o)
  9. toInt(byte[] res)