Java Byte Array to Long bytesToLong(byte[] data)

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

Description

bytes To Long

License

Open Source License

Declaration

public static long bytesToLong(byte[] data) 

Method Source Code

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

public class Main {
    public static long bytesToLong(byte[] data) {
        int offset = 0;
        long a1 = data[offset + 3] & 0xFF;
        long a2 = data[offset + 2] & 0xFF;
        long a3 = data[offset + 1] & 0xFF;
        long a4 = data[offset + 0] & 0xFF;

        long res1 = (a1) + (a2 << 8) + (a3 << 16) + (a4 << 24);
        offset += 4;// w w w .  j  ava 2  s  . c  o  m

        long b1 = data[offset + 3] & 0xFF;
        long b2 = data[offset + 2] & 0xFF;
        long b3 = data[offset + 1] & 0xFF;
        long b4 = data[offset + 0] & 0xFF;

        long res2 = (b1) + (b2 << 8) + (b3 << 16) + (b4 << 24);
        offset += 4;

        return res2 + (res1 << 32);
    }
}

Related

  1. bytesToLong(byte[] bytes)
  2. bytesToLong(byte[] bytes)
  3. bytesToLong(byte[] bytes, int index)
  4. bytesToLong(byte[] bytes, int off)
  5. bytesToLong(byte[] bytes, int off, boolean bigEndian)
  6. bytesToLong(byte[] data)
  7. bytesToLong(byte[] data)
  8. bytesToLong(byte[] data, int offset)
  9. bytesToLong(byte[] inbytes, int shift)