Java Integer Create toInt(final byte[] pBytes)

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

Description

Converts a byte array to an int.

License

Open Source License

Parameter

Parameter Description
pBytes a byte array of length 4

Exception

Parameter Description
ArrayIndexOutOfBoundsException if length is < 4

Return

the bytes converted to an int

Declaration

static int toInt(final byte[] pBytes) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w w  w.  ja  v a 2  s.  com
     * Converts a byte array to an int.
     *
     * @param pBytes a byte array of length 4
     * @return the bytes converted to an int
     *
     * @throws ArrayIndexOutOfBoundsException if length is < 4
     */
    static int toInt(final byte[] pBytes) {
        return (pBytes[0] & 0xff) << 24 | (pBytes[1] & 0xff) << 16
                | (pBytes[2] & 0xff) << 8 | (pBytes[3] & 0xff);
    }
}

Related

  1. toInt(final byte[] buffer, final int offset, final int length)
  2. toInt(final byte[] bytes, final int offset)
  3. toInt(final byte[] bytes, final int offset)
  4. toInt(final byte[] data)
  5. toInt(final byte[] inputBytes, int offset)
  6. toInt(final Double value)
  7. toInt(final double[] a, final int len)
  8. toInt(final int r, final int g, final int b)
  9. toInt(final long a)