Java Array Unpack unpackLong(byte[] arr, int i, int j)

Here you can find the source of unpackLong(byte[] arr, int i, int j)

Description

unpack Long

License

Open Source License

Declaration

private static long unpackLong(byte[] arr, int i, int j) 

Method Source Code

//package com.java2s;
/*//from w  ww .ja va2  s . co m
 * Copyright (c) 2004-2011 Marco Maccaferri and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Marco Maccaferri - initial API and implementation
 */

public class Main {
    private static long unpackLong(byte[] arr, int i, int j) {
        if (arr.length < i + j) {
            return 0L;
        }
        long l = 0L;
        int k = (j - 1) * 8;
        for (int i1 = 0; i1 < j; i1++) {
            l += byteToInt(arr[i + i1]) << k;
            k -= 8;
        }
        return l;
    }

    public static int byteToInt(byte b) {
        int i = b;
        if (b < 0) {
            i = 256 + b;
        }
        return i;
    }
}

Related

  1. unpackInt(byte[] data, int offset)
  2. unpackIntegerByWidth(int len, byte[] buf, int offset)
  3. unpackLE(long aValue, byte[] aBuf, int aOffset)
  4. UnpackLittle32(byte[] bytes, int integer)
  5. unpackLittleEndianLong(byte[] bytes)
  6. unpackw(int[] sourcearray, int arraypos, int[] data, int num, int b)