Java Long to Byte Array longToBytes(long v, final byte[] arr)

Here you can find the source of longToBytes(long v, final byte[] arr)

Description

Returns a Little-Endian byte array extracted from the given long.

License

Apache License

Parameter

Parameter Description
v the given long
arr a given array of 8 bytes that will be returned with the data

Return

a Little-Endian byte array extracted from the given long.

Declaration

public static byte[] longToBytes(long v, final byte[] arr) 

Method Source Code

//package com.java2s;
/*//from w w  w .java2 s  . co  m
 * Copyright 2015-16, Yahoo! Inc.
 * Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms.
 */

public class Main {
    /**
     * Returns a Little-Endian byte array extracted from the given long.
     * @param v the given long
     * @param arr a given array of 8 bytes that will be returned with the data
     * @return a Little-Endian byte array extracted from the given long.
     */
    public static byte[] longToBytes(long v, final byte[] arr) {
        for (int i = 0; i < 8; i++) {
            arr[i] = (byte) (v & 0XFFL);
            v >>>= 8;
        }
        return arr;
    }
}

Related

  1. longToBytes(long number)
  2. longToBytes(long v)
  3. longToBytes(long v)
  4. longToBytes(long v, byte[] b)
  5. longToBytes(long v, byte[] bytes)
  6. longToBytes(long val)
  7. longToBytes(long val)
  8. longToBytes(long value)
  9. longToBytes(long value, byte[] array, int offset)