Here you can find the source of getLong(byte[] buf, int pos, boolean bigEndian)
Parameter | Description |
---|---|
buf | the source byte array |
pos | the position of array to convert from |
bigEndian | true if big endian, false if little endian |
public static final long getLong(byte[] buf, int pos, boolean bigEndian)
//package com.java2s; public class Main { /**//w w w .jav a 2 s .c o m * Convert byte sequence into java long from first 8 bytes * * @param buf the source byte array * @param bigEndian true if big endian, false if little endian * @return short the java long */ public static final long getLong(byte[] buf, boolean bigEndian) { return getLong(buf, 0, bigEndian); } /** * Convert byte sequence into java long. * * @param buf the source byte array * @param pos the position of array to convert from * @param bigEndian true if big endian, false if little endian * @return short the java long */ public static final long getLong(byte[] buf, int pos, boolean bigEndian) { if (bigEndian) { return (((long) buf[pos + 7]) & 0xFF) | ((((long) buf[pos + 6]) & 0xFF) << 8) | ((((long) buf[pos + 5]) & 0xFF) << 16) | ((((long) buf[pos + 4]) & 0xFF) << 24) | ((((long) buf[pos + 3]) & 0xFF) << 32) | ((((long) buf[pos + 2]) & 0xFF) << 40) | ((((long) buf[pos + 1]) & 0xFF) << 48) | ((((long) buf[pos]) & 0xFF) << 56); } else { return (((long) buf[pos]) & 0xFF) | ((((long) buf[pos + 1]) & 0xFF) << 8) | ((((long) buf[pos + 2]) & 0xFF) << 16) | ((((long) buf[pos + 3]) & 0xFF) << 24) | ((((long) buf[pos + 4]) & 0xFF) << 32) | ((((long) buf[pos + 5]) & 0xFF) << 40) | ((((long) buf[pos + 6]) & 0xFF) << 48) | ((((long) buf[pos + 7]) & 0xFF) << 56); } } }