Android Int to Byte Array Convert intToByteArray(int a)

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

Description

Converts an int to a 4 byte array.

Parameter

Parameter Description
a int to convert.

Return

byte array constructed from the passed int.

Declaration

public static byte[] intToByteArray(int a) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  ww  . jav  a2 s  .c o  m*/
     * Converts an int to a 4 byte array.
     *
     * @param a int to convert.
     * @return byte array constructed from the passed int.
     */
    public static byte[] intToByteArray(int a) {
        byte[] ret = new byte[4];
        ret[3] = (byte) (a & 0xFF);
        ret[2] = (byte) ((a >> 8) & 0xFF);
        ret[1] = (byte) ((a >> 16) & 0xFF);
        ret[0] = (byte) ((a >> 24) & 0xFF);
        return ret;
    }
}

Related

  1. int2bytesLE(int val, byte[] b, int off)
  2. int2hex(int i)
  3. intFitsIn(final int value)
  4. intForByte(byte b)
  5. intToByte(int number)
  6. intToByteArray(int i)
  7. intToByteArray(int value)
  8. intToBytes(int i)
  9. intToBytes(int in)