Here you can find the source of toBytes(int is)
public static final byte[] toBytes(int is)
//package com.java2s; public class Main { public static final byte[] toBytes(int is) { byte[] bytes = new byte[4]; for (int i = 0; i < 4; i++) { bytes[3 - i] = (byte) ((is >>> (i << 3)) & 0xFF); }/*from w ww . j a v a 2s . c o m*/ return bytes; } public static final byte[] toBytes(long l) { byte[] bytes = new byte[8]; for (int i = 0; i < 8; i++) { bytes[7 - i] = (byte) ((l >>> (i << 3)) & 0xFF); } return bytes; } public static final byte[] toBytes(short s) { byte[] bytes = new byte[2]; bytes[1] = (byte) (s & 0xFF); bytes[0] = (byte) (s >>> 8); return bytes; } }