Here you can find the source of long2bytes(long i, int byteCount)
public static byte[] long2bytes(long i, int byteCount)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] long2bytes(long i, int byteCount) { byte[] b = new byte[8]; b[7] = (byte) (i); i >>>= 8;//from w ww . j a v a 2s . c om b[6] = (byte) (i); i >>>= 8; b[5] = (byte) (i); i >>>= 8; b[4] = (byte) (i); i >>>= 8; b[3] = (byte) (i); i >>>= 8; b[2] = (byte) (i); i >>>= 8; b[1] = (byte) (i); i >>>= 8; b[0] = (byte) (i); byte[] bytes = new byte[byteCount]; System.arraycopy(b, 8 - byteCount, bytes, 0, byteCount); return bytes; } }