Android Long to Byte Array Convert convertToByteArray(long l)

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

Description

Converts the long to a 4 byte array.

License

Open Source License

Parameter

Parameter Description
l the long to convert

Return

a byte array that is the same as the long

Declaration

public static byte[] convertToByteArray(long l) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  w  w .ja  v  a 2s  . c  o m
     * Converts the long to a 4 byte array. The long must be non negative.
     * @param l the long to convert
     * @return a byte array that is the same as the long
     */
    public static byte[] convertToByteArray(long l) {
        byte[] b = new byte[4];

        b[0] = (byte) (255 & (l >> 24));
        b[1] = (byte) (255 & (l >> 16));
        b[2] = (byte) (255 & (l >> 8));
        b[3] = (byte) (255 & l);

        return b;
    }
}

Related

  1. getBytes(long data)
  2. uint32ToByteArrayLE(long value, byte[] output, int offset)
  3. uint64ToByteArrayLE(long value, byte[] output, int offset)
  4. long2byteArray(final long number, final int length, final boolean swapHalfWord)
  5. long2bytes(long val)
  6. long2bytes(long num)
  7. toBytes(long longValue)
  8. ulong2bytes(long value)
  9. longToBytes(long data, int n)