Here you can find the source of intToBytes(int val)
public static byte[] intToBytes(int val)
//package com.java2s; //License from project: Open Source License public class Main { public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; public static byte[] intToBytes(int val) { if (val == 0) return EMPTY_BYTE_ARRAY; int lenght = 0; int tmpVal = val; while (tmpVal != 0) { tmpVal = tmpVal >> 8;/* www .j a v a 2 s. co m*/ ++lenght; } byte[] result = new byte[lenght]; int index = result.length - 1; while (val != 0) { result[index] = (byte) (val & 0xFF); val = val >> 8; index -= 1; } return result; } }