Java Long to Byte Array longToBytes(long n)

Here you can find the source of longToBytes(long n)

Description

long To Bytes

License

Open Source License

Declaration

public static byte[] longToBytes(long n) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] longToBytes(long n) {
        return longToBytes(n, new byte[8], 0);
    }/*from  w ww . j av a 2  s.  com*/

    public static byte[] longToBytes(long n, byte[] arr, int off) {
        for (int i = 0; i < arr.length; i++) {
            arr[i + off] = (byte) (n >> 8 * i & 0xFF);
        }

        return arr;
    }
}

Related

  1. longToBytes(long l, byte[] bytes, int offset)
  2. longToBytes(long l, byte[] data, int[] offset)
  3. longToBytes(long l, byte[] result)
  4. longToBytes(long ldata, int n)
  5. longToBytes(long lnum, byte[] bytes, int startIndex)
  6. longToBytes(long n)
  7. longToBytes(long n, byte b[], int offset)
  8. longToBytes(long num)
  9. longToBytes(long num, byte[] data, int index)