Here you can find the source of toLong(byte[] b)
Parameter | Description |
---|---|
b | The byte[] to convert. |
public static long toLong(byte[] b)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2007 Boeing.//from w w w . ja v a2 s . c om * 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: * Boeing - initial API and implementation *******************************************************************************/ public class Main { /** * Build a long from first 8 bytes of the array. * * @param b The byte[] to convert. * @return A long. */ public static long toLong(byte[] b) { if (b.length != 8) { throw new IllegalArgumentException(); } return ((long) b[7] & 0xFF) + (((long) b[6] & 0xFF) << 8) + (((long) b[5] & 0xFF) << 16) + (((long) b[4] & 0xFF) << 24) + (((long) b[3] & 0xFF) << 32) + (((long) b[2] & 0xFF) << 40) + (((long) b[1] & 0xFF) << 48) + (((long) b[0] & 0xFF) << 56); } }