Java Double to Byte Array double2bytes(double v)

Here you can find the source of double2bytes(double v)

Description

to byte array.

License

Apache License

Parameter

Parameter Description
v value.

Return

byte[].

Declaration

public static byte[] double2bytes(double v) 

Method Source Code

//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);
    }
}

Related

  1. double2bytearray(double rastervalue)
  2. double2bytes(double v, byte[] b)
  3. double2bytes(double v, int len)
  4. double2bytes(double value)
  5. double2bytes(double x)