Here you can find the source of intToBytes(int n)
public static byte[] intToBytes(int n)
//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; } }