Java Integer Convert To convertInt(byte[] data)

Here you can find the source of convertInt(byte[] data)

Description

convert Int

License

LGPL

Declaration

public static long convertInt(byte[] data) 

Method Source Code

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

public class Main {
    public static long convertInt(byte[] data) {
        return convertInt(data, false);
    }/*from  ww w  .  jav a2s. c  o m*/

    public static long convertInt(byte[] data, boolean reversed) {
        if (!reversed) {
            return ((data[3] & 0xFF) << 24) | ((data[2] & 0xFF) << 16)
                    | ((data[1] & 0xFF) << 8) | (data[0] & 0xFF);
        } else {
            return ((data[0] & 0xFF) << 24) | ((data[1] & 0xFF) << 16)
                    | ((data[2] & 0xFF) << 8) | (data[3] & 0xFF);
        }
    }

    public static long convertInt(byte[] data, int offset, boolean reversed) {
        byte[] target = new byte[4];
        System.arraycopy(data, offset, target, 0, target.length);
        return convertInt(target, reversed);
    }

    public static long convertInt(byte[] data, int offset) {
        byte[] target = new byte[4];
        System.arraycopy(data, offset, target, 0, target.length);
        return convertInt(target, false);
    }
}

Related

  1. convertInt(byte[] data)
  2. convertInt(String str, int defaults)
  3. convertInt(String str, int radix)
  4. convertInt(String value)