Here you can find the source of getByteArrayByLong(long value, int n)
Parameter | Description |
---|---|
value | a parameter |
n | return bytes length |
public static byte[] getByteArrayByLong(long value, int n)
//package com.java2s; public class Main { /**//from w ww . j av a 2s .co m * get bytes by the long value. l before h after * * @param value * @param n * return bytes length * @return */ public static byte[] getByteArrayByLong(long value, int n) { return getByteArrayByLong(value, n, true); } /** * get bytes by the long value * * @param value * @param n * @param isLH * @return */ public static byte[] getByteArrayByLong(long value, int n, boolean isLH) { byte[] dest = new byte[n]; for (int i = 0; i < n; i++) { dest[i] = (byte) ((value >> ((isLH ? i : n - i - 1) * 8)) & 0xFF); } return dest; } }