Android Little Endian Convert longAsLittleEnd(long val)

Here you can find the source of longAsLittleEnd(long val)

Description

Converts a long value to an array in little-endian format.

Declaration

public static byte[] longAsLittleEnd(long val) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww  w. j a va  2 s .co m
     * Converts a long value to an array in little-endian format.
     * \param val The value to be converted.
     * \returns A byte array with the value in little-endian format.
     **/
    public static byte[] longAsLittleEnd(long val) {
        byte[] array = new byte[8];
        return longAsLittleEnd(array, 0, val);
    }

    /**
     * Convert a long value into an array in little-endian format, copying the
     * result in the passed array at the point especified.
     * \param a The array where the converted value should be copied.
     * \param i The starting point, int the array \a a where the copy should
     * start.
     * \param v The value to be converted and copied.
     * \returns \a a.
     **/
    public static byte[] longAsLittleEnd(byte[] a, int i, long v) {
        a[i + 7] = (byte) (0xFF & (v >> 56));
        a[i + 6] = (byte) (0xFF & (v >> 48));
        a[i + 5] = (byte) (0xFF & (v >> 40));
        a[i + 4] = (byte) (0xFF & (v >> 32));
        a[i + 3] = (byte) (0xFF & (v >> 24));
        a[i + 2] = (byte) (0xFF & (v >> 16));
        a[i + 1] = (byte) (0xFF & (v >> 8));
        a[i + 0] = (byte) (0xFF & v);
        return a;
    }
}

Related

  1. charAsLittleEnd(byte[] a, int i, char v)
  2. charAsLittleEnd(char val)
  3. intAsLittleEnd(byte[] a, int i, int v)
  4. intAsLittleEnd(int val)
  5. longAsLittleEnd(byte[] a, int i, long v)
  6. shortAsLittleEnd(byte[] a, int i, short v)
  7. shortAsLittleEnd(short val)
  8. uint32LittleEndian(int value)