Java Long Number Array Create toLongA(byte[] data)

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

Description

to Long A

License

Open Source License

Declaration

public static long[] toLongA(byte[] data) 

Method Source Code

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

public class Main {
    public static long[] toLongA(byte[] data) {
        if (data == null || data.length % 8 != 0)
            return null;
        // ----------
        long[] lngs = new long[data.length / 8];
        for (int i = 0; i < lngs.length; i++) {
            lngs[i] = toLong(new byte[] { data[(i * 8)], data[(i * 8) + 1],
                    data[(i * 8) + 2], data[(i * 8) + 3],
                    data[(i * 8) + 4], data[(i * 8) + 5],
                    data[(i * 8) + 6], data[(i * 8) + 7], });
        }//  w ww  .  ja  v a 2s  . c o  m
        return lngs;
    }

    public static long toLong(byte[] data) {
        if (data == null || data.length != 8)
            return 0x0;
        // ----------
        return (long) (
        // (Below) convert to longs before shift because digits
        //         are lost with ints beyond the 32-bit limit
        (long) (0xff & data[0]) << 56 | (long) (0xff & data[1]) << 48
                | (long) (0xff & data[2]) << 40
                | (long) (0xff & data[3]) << 32
                | (long) (0xff & data[4]) << 24
                | (long) (0xff & data[5]) << 16
                | (long) (0xff & data[6]) << 8 | (long) (0xff & data[7]) << 0);
    }
}

Related

  1. longArray(int len)
  2. LongArrayFrom(long[] array)
  3. LongArrayFrom(long[] array)
  4. toLongArray(boolean[] array)
  5. toLongArray(byte[] array)
  6. toLongArray(byte[] byteArray)
  7. toLongArray(byte[] byteArray)