Here you can find the source of intToBytes(int val, int byteCount)
public static byte[] intToBytes(int val, int byteCount)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { public static byte[] intToBytes(int val, int byteCount) { byte[] buffer = new byte[byteCount]; int[] ints = new int[byteCount]; for (int i = 0; i < byteCount; i++) { ints[i] = val & 0xFF; buffer[byteCount - i - 1] = (byte) ints[i]; val = val >> 8; if (val == 0) { break; }// ww w . j a v a 2 s .c o m } return buffer; } }