Java Convert via ByteBuffer intToBytes(int n)

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

Description

int To Bytes

License

Open Source License

Declaration

public static byte[] intToBytes(int n) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static byte[] intToBytes(int n) {
        byte[] bytes = new byte[Integer.SIZE / 8];

        ByteBuffer b = ByteBuffer.wrap(bytes);

        b.asIntBuffer().put(n);/*  w w  w .  j  a va 2 s .  co m*/

        return bytes;
    }
}

Related

  1. intToBytes(final int i)
  2. intToBytes(final int integer)
  3. intToBytes(final int value)
  4. intToBytes(final int x)
  5. intToBytes(int i, byte[] backingStore, int offset)
  6. intToBytes(int tagId)
  7. intToBytesLE(int value)
  8. intToBytesWithLen(int x, int len)
  9. long2bytes(long num)