Java Byte Array Create toBytes(int intValue)

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

Description

Returns a four byte array representation of the specified integer.

License

Apache License

Parameter

Parameter Description
intValue The integer to be converted.

Return

The byte array representation of the integer.

Declaration

public static byte[] toBytes(int intValue) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   www.ja v a  2s . c  om
     * Returns a four byte array representation of the specified integer.
     *
     * @param intValue The integer to be converted.
     *
     * @return The byte array representation of the integer.
     */
    public static byte[] toBytes(int intValue) {

        byte[] res = new byte[4];
        res[0] = (byte) (intValue >>> 24);
        res[1] = (byte) ((intValue >>> 16) & 0xFF);
        res[2] = (byte) ((intValue >>> 8) & 0xFF);
        res[3] = (byte) (intValue & 0xFF);
        return res;
    }
}

Related

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