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

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

Description

bytes To Long

License

Open Source License

Declaration

public static long bytesToLong(byte[] longBytes) 

Method Source Code

//package com.java2s;
/*// w  ww  .j  a  va  2  s .  com
 * @(#)ByteConvertUtil.java   V0.0.1 2015-2-3, ????1:37:07
 *
 * Copyright 2015 www.ifood517.com. All rights reserved.
 * www.ifood517.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {

    public static long bytesToLong(byte[] longBytes) {
        byte[] data = new byte[8];
        System.arraycopy(longBytes, 0, data, 0, 8);
        int mask = 0xff;
        long temp = 0;
        long res = 0;
        for (int i = 0; i < 8; i++) {
            res <<= 8;
            temp = data[i] & mask;
            res |= temp;
        }
        return res;
    }

    public static long bytesToLong(byte[] longBytes, int index) {
        byte[] data = new byte[8];
        System.arraycopy(longBytes, index, data, 0, 8);
        int mask = 0xff;
        long temp = 0;
        long res = 0;
        for (int i = 0; i < 8; i++) {
            res <<= 8;
            temp = data[i] & mask;
            res |= temp;
        }
        return res;
    }
}

Related

  1. bytesToLong(byte[] data)
  2. bytesToLong(byte[] data)
  3. bytesToLong(byte[] data)
  4. bytesToLong(byte[] data, int offset)
  5. bytesToLong(byte[] inbytes, int shift)
  6. bytesToLong(byte[] p, int offset)
  7. bytesToLong(final byte[] b)
  8. bytesToLong(final byte[] bytes)
  9. bytesToLong(final byte[] bytes)