Java Long to Byte Array longToByteArray(long a, byte[] buf)

Here you can find the source of longToByteArray(long a, byte[] buf)

Description

Converts an long to a byte array with a length of 8.

License

Apache License

Parameter

Parameter Description
a - The long to convert.
buf - The byte array to store the integer in. This must be a length of at least 8.

Declaration

public static void longToByteArray(long a, byte[] buf) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   w ww  .j a v a 2s.  c o  m*/
     * Converts an long to a byte array with a length of 8.
     * @param a - The long to convert.
     * @param buf - The byte array to store the integer in. This must be a length of at least 8.
     */
    public static void longToByteArray(long a, byte[] buf) {
        buf[0] = (byte) ((a >> 56) & 0xFF);
        buf[1] = (byte) ((a >> 48) & 0xFF);
        buf[2] = (byte) ((a >> 40) & 0xFF);
        buf[3] = (byte) ((a >> 32) & 0xFF);
        buf[4] = (byte) ((a >> 24) & 0xFF);
        buf[5] = (byte) ((a >> 16) & 0xFF);
        buf[6] = (byte) ((a >> 8) & 0xFF);
        buf[7] = (byte) (a & 0xFF);
    }
}

Related

  1. longToByteArr(long v)
  2. longToByteArray(final long l)
  3. longToByteArray(final long v, final byte[] buf, final int offset)
  4. longToByteArray(final long val, final byte[] buf, final int offset)
  5. longToByteArray(final long value, final int size)
  6. longToByteArray(long i64)
  7. longToByteArray(long in)
  8. longToByteArray(long input)
  9. longToByteArray(long l)