Here you can find the source of int2Bytes(int i, byte[] bytes, int offset)
public static byte[] int2Bytes(int i, byte[] bytes, int offset) throws Exception
//package com.java2s; //License from project: Open Source License public class Main { public static byte[] int2Bytes(int i, byte[] bytes, int offset) throws Exception { if (bytes == null || bytes.length - offset < 4) throw new Exception("bytes==null||bytes.length-offset<4"); bytes[0 + offset] = (byte) (i & 0xFF); bytes[1 + offset] = (byte) ((i >> 8) & 0xFF); bytes[2 + offset] = (byte) ((i >> 16) & 0xFF); bytes[3 + offset] = (byte) ((i >> 24) & 0xFF); return bytes; }// w ww . jav a2 s.c om public static byte[] int2Bytes(int i) throws Exception { byte[] bytes = new byte[4]; int2Bytes(i, bytes, 0); return bytes; } }