Android Int to Byte Array Convert intToBytes(int i)

Here you can find the source of intToBytes(int i)

Description

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

License

Open Source License

Parameter

Parameter Description
i - The integer to convert.

Return

A byte array containing the 4 bytes of the given integer in big endian order.

Declaration

public static byte[] intToBytes(int i) 

Method Source Code

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

public class Main {
    /**/*from w w w  .  j av  a 2s .c  o m*/
     * Returns a byte array containing the bytes of the given integer in big endian order.
     * 
     * @param i - The integer to convert.
     * 
     * @return A byte array containing the 4 bytes of the given integer in big endian order.
     */
    public static byte[] intToBytes(int i) {
        return new byte[] { (byte) (i >> 24), (byte) (i >> 16 & 0xFF),
                (byte) (i >> 8 & 0xFF), (byte) (i & 0xFF) };
    }
}

Related

  1. intForByte(byte b)
  2. intToByte(int number)
  3. intToByteArray(int a)
  4. intToByteArray(int i)
  5. intToByteArray(int value)
  6. intToBytes(int in)
  7. intToBytes(int n)
  8. intToBytes(int number)
  9. intToBytes(int x)