Here you can find the source of toLong(byte[] bytes, int offset)
Parameter | Description |
---|---|
bytes | a parameter |
offset | a parameter |
public static long toLong(byte[] bytes, int offset)
//package com.java2s; /*/*from w ww . j av a2 s .c om*/ * This file is part of org.kalmeo.util. * * org.kalmeo.util is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * org.kalmeo.util is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with org.kalmeo.util. If not, see <http://www.gnu.org/licenses/>. * * Creation date : 17 janv. 08 * Copyright (c) Kalmeo 2007-2008. All rights reserved. * http://www.kalmeo.org */ public class Main { /** * Convert a byte array to a long value * * @param bytes * @param offset * @return the long value corresponding to the 8 first bytes of the byte * array */ public static long toLong(byte[] bytes, int offset) { int value = 0; if (bytes != null && bytes.length >= 8) { for (int i = 0; i < 8; ++i) { value += (0x000000FF & bytes[offset + i]) << ((7 - i) * 8); } } return value; } }