Here you can find the source of intToBytes(int i)
public static byte[] intToBytes(int i)
//package com.java2s; //License from project: Open Source License public class Main { public static final int NUMBER_OF_BITS_IN_A_BYTE = 8; public static final short MASK_TO_BYTE = 0xFF; public static byte[] intToBytes(int i) { byte[] bytes = new byte[4]; /*//from w w w. j ava 2 s . c o m bytes[0] = (byte)(i & MASK_TO_BYTE); i >>= NUMBER_OF_BITS_IN_A_BYTE; bytes[1] = (byte)(i & MASK_TO_BYTE); i >>= NUMBER_OF_BITS_IN_A_BYTE; bytes[2] = (byte)(i & MASK_TO_BYTE); i >>= NUMBER_OF_BITS_IN_A_BYTE; bytes[3] = (byte)(i & MASK_TO_BYTE); */ bytes[3] = (byte) (i & MASK_TO_BYTE); i >>= NUMBER_OF_BITS_IN_A_BYTE; bytes[2] = (byte) (i & MASK_TO_BYTE); i >>= NUMBER_OF_BITS_IN_A_BYTE; bytes[1] = (byte) (i & MASK_TO_BYTE); i >>= NUMBER_OF_BITS_IN_A_BYTE; bytes[0] = (byte) (i & MASK_TO_BYTE); return bytes; } }