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

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

Description

bytes To Long

License

Open Source License

Declaration

public static long bytesToLong(byte[] bytes) 

Method Source Code

//package com.java2s;

public class Main {
    public static long bytesToLong(byte[] bytes) {
        if (bytes == null || bytes.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 & bytes[0]) << 56 | (long) (0xff & bytes[1]) << 48 | (long) (0xff & bytes[2]) << 40
                | (long) (0xff & bytes[3]) << 32 | (long) (0xff & bytes[4]) << 24 | (long) (0xff & bytes[5]) << 16
                | (long) (0xff & bytes[6]) << 8 | (long) (0xff & bytes[7]) << 0);
    }//from   w w  w  . j  a  va2 s.co  m
}

Related

  1. bytesToLong(byte[] bs)
  2. bytesToLong(byte[] buf, int offset, int length, boolean asc)
  3. bytesToLong(byte[] bytes)
  4. bytesToLong(byte[] bytes)
  5. bytesToLong(byte[] bytes)
  6. bytesToLong(byte[] bytes)
  7. bytesToLong(byte[] bytes)
  8. bytesToLong(byte[] bytes, int index)
  9. bytesToLong(byte[] bytes, int off)