Here you can find the source of bytesToLong(byte[] buf, int offset, int length, boolean asc)
public static long bytesToLong(byte[] buf, int offset, int length, boolean asc)
//package com.java2s; /**/* w w w .j a v a 2 s.co m*/ * @(#)ByteUtils.java, 2013-2-24. * * Copyright 2013 Netease, Inc. All rights reserved. * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ public class Main { public static long bytesToLong(byte[] buf, int offset, int length, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } if (length > 8) { throw new IllegalArgumentException("byte array size > 8 !"); } long l = 0; if (asc) { for (int i = offset; i < offset + length; i++) { l <<= 8; l |= ((long) buf[i] & 0xFF); } } else { for (int i = offset + length - 1; i >= 0; i--) { l <<= 8; l |= ((long) buf[i] & 0xFF); } } return l; } public static long bytesToLong(byte[] buf, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } return bytesToLong(buf, 0, buf.length, asc); } }