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