Android Long to Byte Array Convert longToBytes(long l)

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

Description

Returns a byte array containing the bytes of the given long in big endian order.

License

Open Source License

Parameter

Parameter Description
l - The long to convert

Return

A byte array containing the 8 bytes of the given long in big endian order.

Declaration

public static byte[] longToBytes(long l) 

Method Source Code

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

public class Main {
    /**//from   w  w w.  j  av  a  2s.  co  m
     * Returns a byte array containing the bytes of the given long in big endian order.
     * 
     * @param l - The long to convert
     * 
     * @return A byte array containing the 8 bytes of the given long in big endian order.
     */
    public static byte[] longToBytes(long l) {
        return new byte[] { (byte) (l >> 56), (byte) (l >> 48),
                (byte) (l >> 40), (byte) (l >> 32), (byte) (l >> 24),
                (byte) (l >> 16 & 0xFF), (byte) (l >> 8 & 0xFF),
                (byte) (l & 0xFF) };
    }
}

Related

  1. long2bytesLE(long val, byte[] b, int off)
  2. longFitsIn(final long value)
  3. longToByteArray(long a)
  4. longToByteArray(long l)
  5. longToByteArray(long value)
  6. longToBytes(long x)
  7. longs2bytesBE(long[] val)
  8. longs2bytesLE(long[] val)
  9. toBytes(long value)