Java Convert via ByteBuffer intToBytes(final int x)

Here you can find the source of intToBytes(final int x)

Description

Converts an int value into an array of 4 bytes.

License

Open Source License

Parameter

Parameter Description
x The int.

Return

The bytes.

Declaration

public static byte[] intToBytes(final int x) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**/*www  . j a  va  2  s.c om*/
     * Converts an int value into an array of 4 bytes.
     *
     * @param x The int.
     * @return The bytes.
     */
    public static byte[] intToBytes(final int x) {
        final ByteBuffer buffer = ByteBuffer.allocate(4);
        buffer.putInt(x);
        return buffer.array();
    }
}

Related

  1. intToByteArray(int number)
  2. intToByteArray(int someInt, int byteSize)
  3. intToBytes(final int i)
  4. intToBytes(final int integer)
  5. intToBytes(final int value)
  6. intToBytes(int i, byte[] backingStore, int offset)
  7. intToBytes(int n)
  8. intToBytes(int tagId)
  9. intToBytesLE(int value)