Java Long to Int longToIntBytes(long a)

Here you can find the source of longToIntBytes(long a)

Description

Convert a long value to a 4-byte array.

License

Open Source License

Parameter

Parameter Description
a long integer

Return

byte[4] array

Declaration

public static byte[] longToIntBytes(long a) 

Method Source Code

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

public class Main {
    /**/* w ww.j a  va  2 s .com*/
     * Convert a long value to a 4-byte array.
     * @param a long integer
     * @return byte[4] array
     */
    public static byte[] longToIntBytes(long a) {
        byte[] returnByteArray = new byte[4]; //int is 4 bytes
        returnByteArray[0] = (byte) ((a & 0xff000000) >> 24);
        returnByteArray[1] = (byte) ((a & 0x00ff0000) >> 16);
        returnByteArray[2] = (byte) ((a & 0x0000ff00) >> 8);
        returnByteArray[3] = (byte) ((a & 0x000000ff));
        return returnByteArray;
    }
}

Related

  1. longToInt(long value)
  2. longToInt(long[] values)
  3. longToIntArr(long[] longArr)
  4. longToIntArray(long value)
  5. longToIntBounds(long value)
  6. longToIntClip(final long value)
  7. longToInteger(final long value)
  8. longToInteger(long l)
  9. longToIntHashCode(long value)