Here you can find the source of toBytes(int i)
public static byte[] toBytes(int i)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] toBytes(int i) { int shift = 8; byte[] buf = new byte[4]; int pos = buf.length; int radix = 1 << shift; int mask = radix - 1; do {//from w ww .ja v a 2 s. co m buf[--pos] = (byte) (i & mask); i >>>= shift; } while (i != 0); byte[] result = new byte[buf.length - pos]; System.arraycopy(buf, pos, result, 0, result.length); return result; } }