Here you can find the source of toBytes(int x, byte[] out)
public static byte[] toBytes(int x, byte[] out)
//package com.java2s; public class Main { public static byte[] toBytes(int x, byte[] out) { byte[] intBytes = out == null ? new byte[4] : out; intBytes[3] = (byte) (x >> 24); intBytes[2] = (byte) (x >> 16); intBytes[1] = (byte) (x >> 8); intBytes[0] = (byte) (x >> 0); return intBytes; }//from www.j ava 2 s. c o m public static void toBytes(int[] src, int srcOffset, byte[] dst, int dstOffset, int length) { if (length < 0) throw new IllegalArgumentException( "length must be >= 0, length = " + length); byte[] intBytes = null; for (int i = srcOffset; i < srcOffset + length; i++) { intBytes = toBytes(src[i], intBytes); dst[dstOffset++] = intBytes[0]; dst[dstOffset++] = intBytes[1]; dst[dstOffset++] = intBytes[2]; dst[dstOffset++] = intBytes[3]; } } }