Here you can find the source of bytesToLong(final byte[] b)
Parameter | Description |
---|---|
b | the byte[] to convert to long |
public static long bytesToLong(final byte[] b)
//package com.java2s; /*/*from w w w . j ava2 s.c o m*/ * * JMeta - Meta's java implementation * * Copyright (C) 2013-2015 Pablo Joubert * Copyright (C) 2013-2015 Thomas Lavocat * Copyright (C) 2013-2015 Nicolas Michon * * This file is part of JMeta. * * JMeta is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * JMeta 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ public class Main { /** * Convert a byte array to long. * * @param b the byte[] to convert to long * @return the long value */ public static long bytesToLong(final byte[] b) { return bytesToLong(b, 0); } /** * Convert a byte array to long. * * Only 8 bytes are read from the given array starting at offset. * * @param b the array to convert to long * @param offset the offset in the array * @return the long value */ public static long bytesToLong(final byte[] b, final int offset) { long result = 0; for (int i = offset; i < Long.BYTES; i++) { result <<= Long.BYTES; result |= (b[i] & 0xFF); } return result; } }