Here you can find the source of toByteArray(long value)
public static byte[] toByteArray(long value)
//package com.java2s; public class Main { public static byte[] toByteArray(long value) { byte[] b = new byte[8]; for (int i = 0; i < 8; i++) { int offset = (8 - 1 - i) * 8; b[i] = (byte) (value >>> offset & 0xFF); }//w ww. j av a 2 s . co m return b; } public static byte[] toByteArray(int value) { byte[] b = new byte[4]; for (int i = 0; i < 4; i++) { int offset = (4 - 1 - i) * 8; b[i] = (byte) (value >>> offset & 0xFF); } return b; } public static byte[] toByteArray(short value) { byte[] b = new byte[2]; for (int i = 0; i < 2; i++) { int offset = (2 - 1 - i) * 8; b[i] = (byte) (value >>> offset & 0xFF); } return b; } }