Java Integer Create toInt32(int[] data, int startIndex)

Here you can find the source of toInt32(int[] data, int startIndex)

Description

Extract a signed 32-bit number from an array of int data

License

Apache License

Parameter

Parameter Description
data a parameter
startIndex a parameter

Declaration

public static int toInt32(int[] data, int startIndex) 

Method Source Code

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

public class Main {
    /**/* w w w .j ava2  s .  com*/
     * Extract a signed 32-bit number from an array of int data
     * @param data
     * @param startIndex
     * @return
     */
    public static int toInt32(int[] data, int startIndex) {
        int dataLength = 4;
        int length = data.length;
        if (startIndex < 0 || (startIndex + dataLength) > length) {
            throw new IndexOutOfBoundsException("Index: " + startIndex + ", Length: " + length);
        }

        int value = 0;
        for (int i = 0; i < dataLength; i++) {
            value = (value << 8) + data[startIndex + i];
        }

        return value;
    }
}

Related

  1. toInt(String[] s)
  2. toInt(String[] s, int i)
  3. toInt(T value)
  4. toInt(T[] v)
  5. toInt24(final int value)
  6. toInt32(long x)
  7. toInt32(Object prmIntObject)
  8. toInt4Trim(String value, int _default)
  9. toIntA(byte[] data)