Here you can find the source of longToByte(long x)
public static byte[] longToByte(long x)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] longToByte(long x) { if ((x & 0xFFFFFFFFFFFFFF00L) == 0L) { return new byte[] { (byte) x }; } else if ((x & 0xFFFFFFFFFFFF0000L) == 0L) { return new byte[] { (byte) (x >> 8), (byte) x }; } else if ((x & 0xFFFFFFFFFF000000L) == 0L) { return new byte[] { (byte) (x >> 16), (byte) (x >> 8), (byte) x }; } else if ((x & 0xFFFFFFFF00000000L) == 0L) { return new byte[] { (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x }; } else if ((x & 0xFFFFFF0000000000L) == 0L) { return new byte[] { (byte) (x >> 32), (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x }; } else if ((x & 0xFFFF000000000000L) == 0L) { return new byte[] { (byte) (x >> 40), (byte) (x >> 32), (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x }; } else if ((x & 0xFF00000000000000L) == 0L) { return new byte[] { (byte) (x >> 48), (byte) (x >> 40), (byte) (x >> 32), (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x }; }//from w ww.j a va 2s .c o m return new byte[] { (byte) (x >> 56), (byte) (x >> 48), (byte) (x >> 40), (byte) (x >> 32), (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x }; } }