Java Byte Array to Long bytes2long(byte[] bytes, boolean bigEndian)

Here you can find the source of bytes2long(byte[] bytes, boolean bigEndian)

Description

byteslong

License

Apache License

Declaration

public static long bytes2long(byte[] bytes, boolean bigEndian) 

Method Source Code

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

public class Main {
    public static long bytes2long(byte[] bytes, boolean bigEndian) {
        return bytes2long(bytes, 0, bigEndian);
    }/*from   w ww  . j av  a2 s . co  m*/

    public static long bytes2long(byte[] bytes, int offset, boolean bigEndian) {
        long val = 0;

        if (bigEndian) {
            for (int i = 0; i < 8; i++) {
                val |= (((long) bytes[i + offset]) & 0xffL) << ((7 - i) * 8);
            }
        } else {
            for (int i = 0; i < 8; i++) {
                val |= (((long) bytes[i + offset]) & 0xffL) << (i * 8);
            }
        }

        return val;
    }
}

Related

  1. bytes2long(byte[] bytes)
  2. bytes2Long(byte[] bytes)
  3. bytes2Long(byte[] bytes)
  4. bytes2long(byte[] bytes)
  5. bytes2Long(byte[] bytes)
  6. bytes2Long(byte[] bytes, int offset)
  7. bytes2Long(final byte[] b)
  8. bytes2long(final byte[] bytes, final int start)
  9. bytesToLong(byte a, byte b, byte c, byte d)