Here you can find the source of longFromBytes(byte[] bytes, int index)
Parameter | Description |
---|---|
bytes | an 8-byte array |
index | the index offset into the byte array to sample |
public static long longFromBytes(byte[] bytes, int index)
//package com.java2s; /*//from w w w . j av a2 s . c o m * Copyright (C) 2014 Jesse Caulfield * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Unsigned Long from 8 bytes * * @param bytes an 8-byte array * @param index the index offset into the byte array to sample * @return Unsigned Long */ public static long longFromBytes(byte[] bytes, int index) { if ((bytes == null) || (bytes.length < 7)) { return -1; } int idx = index; long val = 0; for (int i = 0; i < 8; i++) { if (i < 7) { val |= (((long) bytes[idx + i] & 0x000000ff) << (64 - ((i + 1) * 8))); } else { val |= ((long) bytes[idx + i] & 0x000000ff); } } return val; } }