Here you can find the source of longToByteArray(long value)
private static byte[] longToByteArray(long value)
//package com.java2s; //License from project: LGPL public class Main { private static byte[] longToByteArray(long value) { byte[] result = new byte[8]; // FYI - The effect of this operation is to break // down the long into an array of eight bytes. ////from ww w . j av a 2s . com // What's going on: The FF selects selects the byte // of interest within value. The the >> shifts the // target bits to the right the desired result. The // shift ensures the result will fit into a single // 8-bit byte. Depending upon the byte of interest // it must be shifted appropriately so it's always // in the lower-order 8-bits. result[0] = (byte) (value & 0x00000000000000FFL); result[1] = (byte) ((value & 0x000000000000FF00L) >> 8); result[2] = (byte) ((value & 0x0000000000FF0000L) >> 16); result[3] = (byte) ((value & 0x00000000FF000000L) >> 24); result[4] = (byte) ((value & 0x000000FF00000000L) >> 32); result[5] = (byte) ((value & 0x0000FF0000000000L) >> 40); result[6] = (byte) ((value & 0x00FF000000000000L) >> 48); result[7] = (byte) ((value & 0xFF00000000000000L) >> 56); return result; } }