Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; public class Main { public static byte[] convertIntToByteArray(int my_int) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); dos.writeInt(my_int); dos.close(); byte[] int_bytes = bos.toByteArray(); bos.close(); return int_bytes; } }