Java Long Number Create toLong(byte[] input)

Here you can find the source of toLong(byte[] input)

Description

Converts a given byte array to a long .

License

BSD License

Parameter

Parameter Description
input A network byte-ordered representation of a long .

Return

The long value represented by the input array

Declaration

public static long toLong(byte[] input) 

Method Source Code

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

public class Main {
    /**/*from  w ww.  j a  va 2  s .c  om*/
     * Converts a given byte array to a {@code long}. Bytes are expected in
     * network byte
     *
     * @param input A network byte-ordered representation of a {@code long}.
     * @return The {@code long} value represented by the input array
     */
    public static long toLong(byte[] input) {
        assert input.length == 8 : "toLong(): Byte array length must be 8.";
        long output = 0;
        output = ((long) (input[0] & 0xff) << 56);
        output |= ((long) (input[1] & 0xff) << 48);
        output |= ((long) (input[2] & 0xff) << 40);
        output |= ((long) (input[3] & 0xff) << 32);
        output |= ((long) (input[4] & 0xff) << 24);
        output |= ((long) (input[5] & 0xff) << 16);
        output |= ((long) (input[6] & 0xff) << 8);
        output |= (input[7] & 0xff);
        return output;
    }
}

Related

  1. toLong(byte[] data)
  2. toLong(byte[] data)
  3. toLong(byte[] data)
  4. toLong(byte[] data)
  5. toLong(byte[] in)
  6. toLong(byte[] key)
  7. toLong(byte[] memory, int index)
  8. toLong(byte[] n)
  9. toLong(byte[] readBuffer, int o)