Here you can find the source of bytesToLong(byte[] b)
Parameter | Description |
---|---|
bytes | a parameter |
public final static long bytesToLong(byte[] b)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004,2009 Actuate Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w. j a v a2 s. c o m*/ * Actuate Corporation - initial API and implementation *******************************************************************************/ public class Main { /** * Assemble eight bytes to an long value, make sure that the passed bytes * length larger than 8. * * @param bytes * @return int value of bytes */ public final static long bytesToLong(byte[] b) { assert b.length >= 8; return ((b[0] & 0xFFL) << 56) + ((b[1] & 0xFFL) << 48) + ((b[2] & 0xFFL) << 40) + ((b[3] & 0xFFL) << 32) + ((b[4] & 0xFFL) << 24) + ((b[5] & 0xFFL) << 16) + ((b[6] & 0xFFL) << 8) + ((b[7] & 0xFFL) << 0); } public final static long bytesToLong(byte[] b, int off) { assert b.length - off >= 8; return ((b[off++] & 0xFFL) << 56) + ((b[off++] & 0xFFL) << 48) + ((b[off++] & 0xFFL) << 40) + ((b[off++] & 0xFFL) << 32) + ((b[off++] & 0xFFL) << 24) + ((b[off++] & 0xFFL) << 16) + ((b[off++] & 0xFFL) << 8) + ((b[off] & 0xFFL) << 0); } }