Here you can find the source of long2bytes(long v)
Parameter | Description |
---|---|
v | value. |
public static byte[] long2bytes(long v)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .jav a 2s . c o m*/ * to byte array. * * @param v value. * @return byte[]. */ public static byte[] long2bytes(long v) { byte[] ret = { 0, 0, 0, 0, 0, 0, 0, 0 }; long2bytes(v, ret); return ret; } /** * to byte array. * * @param v value. * @param b byte array. */ public static void long2bytes(long v, byte[] b) { long2bytes(v, b, 0); } /** * to byte array. * * @param v value. * @param b byte array. * @param off array offset. */ public static void long2bytes(long v, byte[] b, int off) { b[off + 7] = (byte) v; b[off + 6] = (byte) (v >>> 8); b[off + 5] = (byte) (v >>> 16); b[off + 4] = (byte) (v >>> 24); b[off + 3] = (byte) (v >>> 32); b[off + 2] = (byte) (v >>> 40); b[off + 1] = (byte) (v >>> 48); b[off + 0] = (byte) (v >>> 56); } }