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

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

Description

Converts a byte array to a long number

License

Open Source License

Parameter

Parameter Description
bytes a parameter

Return

long as bytes value

Declaration

public static long bytesToLong(byte[] bytes) 

Method Source Code

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

public class Main {
    /**/*ww w. j a va2  s  .  c  o  m*/
     * Converts a byte array to a long number
     * @param bytes
     * @return long  as bytes value
     */
    public static long bytesToLong(byte[] bytes) {
        long n = ((long) (bytes[7])) & 0xFFL;
        n |= (((long) bytes[6]) << 8) & 0xFF00L;
        n |= (((long) bytes[5]) << 16) & 0xFF0000L;
        n |= (((long) bytes[4]) << 24) & 0xFF000000L;
        n |= (((long) bytes[3]) << 32) & 0xFF00000000L;
        n |= (((long) bytes[2]) << 40) & 0xFF0000000000L;
        n |= (((long) bytes[1]) << 48) & 0xFF000000000000L;
        n |= (((long) bytes[0]) << 56) & 0xFF00000000000000L;
        return n;
    }
}

Related

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