Java Long Number Create convertLong(byte[] data, int offset)

Here you can find the source of convertLong(byte[] data, int offset)

Description

This method uses a leading 1 byte[] This method converts a 4 byte integer that is stored in a byte[] and converts it to a decimal int

License

Open Source License

Parameter

Parameter Description
data the byte[] that stores the Integer of interest
offset the offset into the data[]

Return

a decimal Integer that is equal to the byte[] integer

Declaration

public static long convertLong(byte[] data, int offset) 

Method Source Code

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

public class Main {
    /**/* ww  w. j  a  v  a 2 s.  c o m*/
     * This method uses a leading 1 byte[]
     * This method converts a 4 byte int to a decimal int
     * @param data a byte[] storing a 4 byte int
     * @return a decimal Integer that is equal to the byte[] integer
     */
    public static long convertLong(byte[] data) {
        long value = 0;
        for (int i = 0; i < data.length; i++) {
            value = (value << 8) + (data[i] & 0xff);
        }
        return value;
    }

    /**
     * This method uses a leading 1 byte[]
     * This method converts a 4 byte integer that is stored in a byte[] and converts it to a decimal int
     * @param data the byte[] that stores the Integer of interest
     * @param offset the offset into the data[]
     * @return a decimal Integer that is equal to the byte[] integer
     */
    public static long convertLong(byte[] data, int offset) {
        byte[] target = new byte[4];
        System.arraycopy(data, offset, target, 0, target.length);
        return convertLong(target);
    }
}

Related

  1. convertLong(long v, boolean isLE)
  2. convertLong2FourBytes(long data)
  3. convertLongAddressToBuf(long ipAddress)
  4. convertLongArray(long[] arr)