Java Convert via ByteBuffer intToByteArray(int number)

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

Description

Returns a int as a byte array.

License

Open Source License

Parameter

Parameter Description
number int to be converted

Return

byte array with size of 4

Declaration

public static byte[] intToByteArray(int number) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**/* www . j  av  a 2  s. co m*/
     * Returns a int as a byte array.
     *
     * @param number int to be converted
     * @return byte array with size of 4
     */
    public static byte[] intToByteArray(int number) {
        return ByteBuffer.allocate(Integer.BYTES).putInt(number).array();
    }
}

Related

  1. intsToBytes(int[] n)
  2. IntToBArray(int src)
  3. intToByte(int[] intArray)
  4. intToByteArray(int integer)
  5. intToByteArray(int l)
  6. intToByteArray(int someInt, int byteSize)
  7. intToBytes(final int i)
  8. intToBytes(final int integer)
  9. intToBytes(final int value)