Java Byte Array Create toBytes(int integer)

Here you can find the source of toBytes(int integer)

Description

Convert integer to byte array
sample: 0x037fb4c7 => {03, 7f, b4, c7}

License

Open Source License

Parameter

Parameter Description
integer a parameter

Declaration

public static final byte[] toBytes(int integer) 

Method Source Code

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

public class Main {
    /**/*from  w ww .j av a 2 s. c o  m*/
     * Convert integer to byte array<br/>
     * sample: 0x037fb4c7 => {03, 7f, b4, c7}
     * @param integer
     * @return
     */
    public static final byte[] toBytes(int integer) {
        byte[] result = new byte[4];

        result[0] = (byte) (integer >> 24);
        result[1] = (byte) (integer >> 16);
        result[2] = (byte) (integer >> 8);
        result[3] = (byte) (integer /* >> 0 */);

        return result;

        // return BigInteger.valueOf(integer).toByteArray();
    }
}

Related

  1. toBytes(int i)
  2. toBytes(int i)
  3. toBytes(int i)
  4. toBytes(int i)
  5. toBytes(int i)
  6. toBytes(int integer)
  7. toBytes(int intValue)
  8. toBytes(int is)
  9. toBytes(int megabytes)