Java Long to Byte Array longToByteArr(long v)

Here you can find the source of longToByteArr(long v)

Description

long To Byte Arr

License

Open Source License

Declaration

public static byte[] longToByteArr(long v) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] longToByteArr(long v) {
        return new byte[] { (byte) (v >>> 56), (byte) (v >>> 48), (byte) (v >>> 40), (byte) (v >>> 32),
                (byte) (v >>> 24), (byte) (v >>> 16), (byte) (v >>> 8), (byte) (v) };
    }/*from  w w w. ja  v a  2 s.c  om*/

    public static byte[] longToByteArr(long v, byte[] arr, int position) {
        for (int i = 56; i >= 0; i -= 8) {
            arr[position--] = (byte) (v >>> i);
        }
        return arr;
    }
}

Related

  1. long2bytes(long value, byte[] bytes, int off)
  2. long2bytes(long value, byte[] bytes, int offset)
  3. long2bytes(long x)
  4. long2bytes(long... numbers)
  5. long2bytesBE(long val, byte[] b, int off)
  6. longToByteArray(final long l)
  7. longToByteArray(final long v, final byte[] buf, final int offset)
  8. longToByteArray(final long val, final byte[] buf, final int offset)
  9. longToByteArray(final long value, final int size)