Android Little Ending to Long Convert littleEndToLong(byte[] array, int start)

Here you can find the source of littleEndToLong(byte[] array, int start)

Description

Convert byte array in a integral type.

Declaration

public static long littleEndToLong(byte[] array, int start) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  ww w.j  a va 2 s. c  om*/
     * Convert byte array in a integral type.
     * The conversion is done in the \b little-endian format. Java uses the \b
     * big-endian format as default.
     * \param array The \b byte array to be converted.
     * \param start Index of the first element of the \a array array where the
     * conversion should start.
     * \return The integral type with the result of the conversion.
     * \remarks This function assumes that the sequency of bytes in array is in
     * the \b little-endian format (most significant bytes first).
     **/
    public static long littleEndToLong(byte[] array, int start) {
        return (((long) (array[start + 7] & 0xFF) << 56)
                | ((long) (array[start + 6] & 0xFF) << 48)
                | ((long) (array[start + 5] & 0xFF) << 40)
                | ((long) (array[start + 4] & 0xFF) << 32)
                | ((long) (array[start + 3] & 0xFF) << 24)
                | ((long) (array[start + 2] & 0xFF) << 16)
                | ((long) (array[start + 1] & 0xFF) << 8) | ((long) (array[start + 0] & 0xFF)));
    }
}