Java Integer to Byte Array intToByteArray(int a)

Here you can find the source of intToByteArray(int a)

Description

Returns four bytes represented by int.

License

Open Source License

Parameter

Parameter Description
a int.

Return

Four bytes representd by int.

Declaration

public static byte[] intToByteArray(int a) 

Method Source Code

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

public class Main {
    /**//from  w  w w.jav  a  2s .  com
     * Returns four bytes represented by int.
     * 
     * @param a int.
     * @return Four bytes representd by int.
     */
    public static byte[] intToByteArray(int a) {
        return new byte[] { (byte) ((a >> 24) & 0xFF),
                (byte) ((a >> 16) & 0xFF), (byte) ((a >> 8) & 0xFF),
                (byte) (a & 0xFF) };
    }
}

Related

  1. intToByteArray(final int v, final byte[] buf, final int offset)
  2. intToByteArray(final int val, final byte[] buf, final int offset)
  3. intToByteArray(final int value)
  4. intToByteArray(final int x)
  5. intToByteArray(final int x, final byte[] dst, final int offset)
  6. intToByteArray(int a)
  7. intToByteArray(int bytes)
  8. intToByteArray(int data)
  9. intToByteArray(int i)