Here you can find the source of bytesToLong(byte[] bytes, int off)
Parameter | Description |
---|---|
bytes | Array of bytes. |
off | Offset in bytes array. |
public static long bytesToLong(byte[] bytes, int off)
//package com.java2s; // Copyright (C) GridGain Systems Licensed under GPLv3, http://www.gnu.org/licenses/gpl.html public class Main { /**//from www.j a va2 s . c om * Constructs {@code long} from byte array. * * @param bytes Array of bytes. * @param off Offset in {@code bytes} array. * @return Long value. */ public static long bytesToLong(byte[] bytes, int off) { return fromBytes(bytes, off, 8); } /** * Constructs {@code long} from byte array. The first byte in array is the highest byte in result. * * @param bytes Array of bytes. * @param offset Offset in {@code bytes} array. * @param limit Amount of bytes to use in the source array. * @return Unsigned long value. */ private static long fromBytes(byte[] bytes, int offset, int limit) { assert bytes != null; assert limit <= 8; assert bytes.length >= offset + limit; long res = 0; for (int i = 0; i < limit; i++) { res <<= 8; res |= bytes[offset + i] & 0xFF; } return res; } }