Here you can find the source of toByteArray(int num)
static byte[] toByteArray(int num)
//package com.java2s; //License from project: Apache License public class Main { static byte[] toByteArray(int num) { final int INT_BYTES = Integer.SIZE / 8; byte[] bytes = new byte[INT_BYTES]; for (int i = 0; i < INT_BYTES; i++) { bytes[(INT_BYTES - 1) - i] = (byte) (num >>> 8 * i); }//from w w w.j a v a 2 s . co m return bytes; } static byte[] toByteArray(long num) { final int LONG_BYTES = Long.SIZE / 8; byte[] bytes = new byte[LONG_BYTES]; for (int i = 0; i < LONG_BYTES; i++) { bytes[(LONG_BYTES - 1) - i] = (byte) (num >>> 8 * i); } return bytes; } }