Here you can find the source of longToBytes(final long value)
public static byte[] longToBytes(final long value)
//package com.java2s; /*/*from w w w. j ava 2 s . c o m*/ * Copyright (c) 2014. Donald Trummell. All Rights Reserved. Permission to use, * copy, modify, and distribute this software and its documentation for * educational, research, and not-for-profit purposes, without fee and without a * signed licensing agreement, is hereby granted, provided that the above * copyright notice, and this paragraph, appear in all copies, modifications, * and distributions. Contact dtrummell@gmail.com for commercial licensing * opportunities. */ import java.nio.ByteBuffer; public class Main { public static final int BYTES_IN_LONG = Long .numberOfLeadingZeros(new Long(0l)) / 8; public static byte[] longToBytes(final long value) { return ByteBuffer.allocate(BYTES_IN_LONG).putLong(value).array(); } }