Android Big Endian Convert longAsBigEnd(byte[] a, int i, long v)

Here you can find the source of longAsBigEnd(byte[] a, int i, long v)

Description

Convert a long value into an array in big-endian format, copying the result in the passed array at the point especified.

Declaration

public static byte[] longAsBigEnd(byte[] a, int i, long v) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*www  .  j  ava2 s. c om*/
     * Convert a long value into an array in big-endian format.
     * \param val The value to be converted.
     * \returns An array with the value \a val in big-endian format. This
     * array will have 8 bytes long.
     **/
    public static byte[] longAsBigEnd(long val) {
        byte[] array = new byte[8];
        return longAsBigEnd(array, 0, val);
    }

    /**
     * Convert a long value into an array in big-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[] longAsBigEnd(byte[] a, int i, long v) {
        a[i + 0] = (byte) (0xFF & (v >> 56));
        a[i + 1] = (byte) (0xFF & (v >> 48));
        a[i + 2] = (byte) (0xFF & (v >> 40));
        a[i + 3] = (byte) (0xFF & (v >> 32));
        a[i + 4] = (byte) (0xFF & (v >> 24));
        a[i + 5] = (byte) (0xFF & (v >> 16));
        a[i + 6] = (byte) (0xFF & (v >> 8));
        a[i + 7] = (byte) (0xFF & v);
        return a;
    }
}

Related

  1. charAsBigEnd(byte[] a, int i, char v)
  2. charAsBigEnd(char val)
  3. intAsBigEnd(byte[] a, int i, int v)
  4. intAsBigEnd(int val)
  5. longAsBigEnd(long val)
  6. shortAsBigEnd(byte[] a, int i, short v)
  7. shortAsBigEnd(short val)
  8. toBigEndianByteArray(int val, byte[] b, int pos)