Here you can find the source of longToBytes(long number)
Parameter | Description |
---|---|
number | a parameter |
public static byte[] longToBytes(long number)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w . j a v a 2 s . co m * Converts a long number to a byte array * @param number * @return bytes as long value */ public static byte[] longToBytes(long number) { byte[] ret = new byte[8]; ret[0] = (byte) ((number >>> 8 * 7) & 0xFF); ret[1] = (byte) ((number >> 8 * 6) & 0xFF); ret[2] = (byte) ((number >> 8 * 5) & 0xFF); ret[3] = (byte) ((number >> 8 * 4) & 0xFF); ret[4] = (byte) ((number >>> 8 * 3) & 0xFF); ret[5] = (byte) ((number >> 8 * 2) & 0xFF); ret[6] = (byte) ((number >> 8 * 1) & 0xFF); ret[7] = (byte) (number & 0xFF); return ret; } }