Here you can find the source of toArray(long value, byte[] dest, int offset, int length)
Parameter | Description |
---|---|
value | The long value |
dest | The destination array |
offset | The offset inside the array |
length | The length of the array |
public static void toArray(long value, byte[] dest, int offset, int length)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w. j av a2s . c o m*/ * Converts a long value to a short array.<br> * The long value could be positive or negative. The result will be set into * the array from lowest to highest, truncating bytes if the length of the * array is too small. The array will be sorted in Low-To-High-Order! * * e.g.:<br> * 530 dec is 0212 hex, so with length 2 it will be [0]=0x12,[1]=0x02<br> * 530 dec is 0212 hex, so with length 3 it will be * [0]=0x12,[1]=0x02,[2]=0x00<br> * * @param value * The long value * @param dest * The destination array * @param offset * The offset inside the array * @param length * The length of the array */ public static void toArray(long value, byte[] dest, int offset, int length) { for (int x = 0; x < length; x++) { dest[offset + x] = (byte) (value >>> (8 * x)); } } /** * Converts a float value to a short array.<br> * The float value could be positive or negative. The result will be set * into the array from lowest to highest, truncating bytes if the length of * the array is too small. The array will be sorted in Low-To-High-Order! * * e.g.:<br> * 530 dec is 0212 hex, so with length 2 it will be [0]=0x12,[1]=0x02<br> * 530 dec is 0212 hex, so with length 3 it will be * [0]=0x12,[1]=0x02,[2]=0x00<br> * * @param value * The float value * @param dest * The destination array * @param offset * The offset inside the array * @param length * The length of the array */ public static void toArray(float value, byte[] dest, int offset, int length) { toArray(convertFloatToHex(value), dest, offset, length); } /** * Convert a float value to a hex value given as a long.<br> * * @param floatValue * The float value * @return The hex value */ public static long convertFloatToHex(float floatValue) { return Float.floatToIntBits(floatValue) & 0xFFFFFFFFL; } }