Java Convert via ByteBuffer longToBytes(long aLong)

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

Description

Convert a long to 8 bytes.

License

Apache License

Parameter

Parameter Description
aLong A long.

Return

A 2's compliment byte representation of the long.

Declaration

public static byte[] longToBytes(long aLong) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    /**/*from www  . ja v a 2s .c om*/
     * Convert a long to 8 bytes.
     *
     * @param aLong A long.
     * @return A 2's compliment byte representation of the long.
     */
    public static byte[] longToBytes(long aLong) {
        return ByteBuffer.allocate(8).putLong(aLong).array();
    }
}

Related

  1. longToByteArray(long l)
  2. longToByteArray(long value)
  3. longToByteArray(long value)
  4. longToByteArray(long[] array)
  5. longToBytes(final long value)
  6. longToBytes(long l)
  7. longToBytes(long l, int size)
  8. longToBytes(long x)
  9. longToBytes(long x, byte[] dest, int offset)