Here you can find the source of toLong(final byte[] data)
Parameter | Description |
---|---|
data | byte array to convert |
public static long toLong(final byte[] data)
//package com.java2s; /*//from www. ja va 2 s . c o m * File: HashFunctionUtil.java * Authors: Kevin R. Dixon * Company: Sandia National Laboratories * Project: Cognitive Foundry * * Copyright Jan 26, 2011, Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the U.S. Government. * Export of this program may require a license from the United States * Government. See CopyrightHistory.txt for complete details. * */ public class Main { /** * Converts the 8-byte value to a Big Endian long * @param data * byte array to convert * @return * Long of the given byte array */ public static long toLong(final byte[] data) { if (data.length != 8) { throw new IllegalArgumentException("data must be of length 8"); } return toLong(data, 0); } /** * Converts the 8-byte value at "offset" to a Big Endian long * @param data * byte array to convert * @param offset * Offset into the byte array * @return * Long at the given offset */ public static long toLong(final byte[] data, final int offset) { return ((data[offset] & 0xffL) << 56) | ((data[offset + 1] & 0xffL) << 48) | ((data[offset + 2] & 0xffL) << 40) | ((data[offset + 3] & 0xffL) << 32) | ((data[offset + 4] & 0xffL) << 24) | ((data[offset + 5] & 0xffL) << 16) | ((data[offset + 6] & 0xffL) << 8) | ((data[offset + 7] & 0xffL)); } }