Java tutorial
//package com.java2s; //License from project: Apache License import java.math.BigInteger; public class Main { public static byte[] toBytes(long num) { BigInteger a = BigInteger.valueOf(num); byte[] temp = a.toByteArray(); byte[] tr = new byte[temp.length]; for (int i = 0; i < tr.length; i++) { tr[i] = temp[temp.length - 1 - i]; } return tr; } }