Here you can find the source of long2byte(byte[] b, long a)
Parameter | Description |
---|---|
b | a parameter |
a | a parameter |
public static void long2byte(byte[] b, long a)
//package com.java2s; public class Main { /**/*w ww. j a v a 2 s. co m*/ * Converts long representation to bytes. * Uses provided byte[] with length at least 4. * * LSB in long will be 1st bit in byte[0]. * @param b * @param a */ public static void long2byte(byte[] b, long a) { b[0] = (byte) (a & 0xFF); b[1] = (byte) ((a >>> 8) & 0xFF); b[2] = (byte) ((a >>> 16) & 0xFF); b[3] = (byte) ((a >>> 24) & 0xFF); } /** * Converts long representation to bytes. * * LSB in long will be 1st bit in byte[0]. */ public static byte[] long2byte(long a) { byte[] b = new byte[4]; long2byte(b, a); return b; } /** * Converts long representation to bytes, returns selected part of long. * * LSB in long will be 1st bit in byte[0]. * @param a * @param idx * @return */ public static byte long2byte(long a, int idx) { return (byte) ((a >>> (8 * idx)) & 0xFF); } }