Java Long Number Create toLong(byte[] bytes)

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

Description

to Long

License

Open Source License

Declaration

public static long toLong(byte[] bytes) 

Method Source Code

//package com.java2s;
/**//from ww  w .j ava  2s .co  m
 * Copyright 2012-2013 Johns Hopkins University HLTCOE. All rights reserved.
 * This software is released under the 2-clause BSD license.
 * See LICENSE in the project root directory.
 */

public class Main {
    public static long toLong(byte[] bytes) {
        assert (bytes.length >= 8);
        return ((0xffL & bytes[0]) << 56 | (0xffL & bytes[1]) << 48 | (0xffL & bytes[2]) << 40
                | (0xffL & bytes[3]) << 32 | (0xffL & bytes[4]) << 24 | (0xffL & bytes[5]) << 16
                | (0xffL & bytes[6]) << 8 | (0xffL & bytes[7]) << 0);
    }

    public static long toLong(byte[] bytes, int offset) {
        assert (bytes.length >= (8 + offset));
        return ((0xffL & bytes[0 + offset]) << 56 | (0xffL & bytes[1 + offset]) << 48
                | (0xffL & bytes[2 + offset]) << 40 | (0xffL & bytes[3 + offset]) << 32
                | (0xffL & bytes[4 + offset]) << 24 | (0xffL & bytes[5 + offset]) << 16
                | (0xffL & bytes[6 + offset]) << 8 | (0xffL & bytes[7 + offset]) << 0);
    }
}

Related

  1. toLong(byte[] buf, int off)
  2. toLong(byte[] buf, int pos)
  3. toLong(byte[] byteArray)
  4. toLong(byte[] bytes)
  5. toLong(byte[] bytes)
  6. toLong(byte[] bytes)
  7. toLong(byte[] bytes)
  8. toLong(byte[] bytes)
  9. toLong(byte[] bytes)