Here you can find the source of doubleToBytes(double dnum, byte[] bytes, int startIndex)
Parameter | Description |
---|---|
dnum | the double given to convert |
bytes | the bytes where to store the result |
startIndex | the starting index of the array where the result is stored. |
public static int doubleToBytes(double dnum, byte[] bytes, int startIndex)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a va 2 s . c o m * Given a double, convert it into a byte array * * @param dnum * the double given to convert * @param bytes * the bytes where to store the result * @param startIndex * the starting index of the array where the result is stored. * @ret the index of the array after storing this double */ public static int doubleToBytes(double dnum, byte[] bytes, int startIndex) { return longToBytes(Double.doubleToLongBits(dnum), bytes, startIndex); } /** * Given a long, convert it into a byte array * * @param lnum * the long given to convert * @param bytes * the bytes where to store the result * @param startIndex * the starting index of the array where the result is stored. * @ret the index of the array after storing this long */ public static int longToBytes(long lnum, byte[] bytes, int startIndex) { for (int i = 0; i < 8; i++) bytes[startIndex + i] = (byte) ((lnum >> (i * 8)) & 0xff); return startIndex + 8; } }