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 step = 8; for (; (i >>> step) > 0 && step < 32; step += 8) ;/* w w w. j a v a 2 s .com*/ byte[] b = new byte[step / 8]; for (int x = 0, move = step - 8; x < (step / 8); x++, move -= 8) { b[x] = (byte) (i >>> move); } return b; } public static byte[] toBytes(long l) { int step = 8; for (; (l >>> step) > 0 && step < 64; step += 8) ; byte[] b = new byte[step / 8]; for (int x = 0, move = step - 8; x < (step / 8); x++, move -= 8) { b[x] = (byte) (l >>> move); } return b; } }