Java Double to Byte Array doubleToBytes(final double d)

Here you can find the source of doubleToBytes(final double d)

Description

double To Bytes

License

Open Source License

Declaration

static public byte[] doubleToBytes(final double d) 

Method Source Code

//package com.java2s;
/*/*from   w w  w .  j a v a  2s .c  o  m*/
 *    AsTeRICS - Assistive Technology Rapid Integration and Construction Set
 *
 *
 *        d8888      88888888888       8888888b.  8888888 .d8888b.   .d8888b.
 *       d88888          888           888   Y88b   888  d88P  Y88b d88P  Y88b
 *      d88P888          888           888    888   888  888    888 Y88b.    
 *     d88P 888 .d8888b  888   .d88b.  888   d88P   888  888         "Y888b. 
 *    d88P  888 88K      888  d8P  Y8b 8888888P"    888  888            "Y88b.
 *   d88P   888 "Y8888b. 888  88888888 888 T88b     888  888    888       "888
 *  d8888888888      X88 888  Y8b.     888  T88b    888  Y88b  d88P Y88b  d88P
 * d88P     888  88888P' 888   "Y8888  888   T88b 8888888 "Y8888P"   "Y8888P"
 *
 *
 *                    homepage: http://www.asterics.org
 *
 *     This project has been partly funded by the European Commission,
 *                      Grant Agreement Number 247730
 *  
 *  
 *         Dual License: MIT or GPL v3.0 with "CLASSPATH" exception
 *         (please refer to the folder LICENSE)
 *
 */

public class Main {
    static public byte[] doubleToBytes(final double d) {
        long l = Double.doubleToRawLongBits(d);
        return longToBytes(l);
    }

    static public byte[] longToBytes(final long l) {
        return new byte[] { (byte) (l >>> 56), (byte) (l >>> 48), (byte) (l >>> 40), (byte) (l >>> 32),
                (byte) (l >>> 24), (byte) (l >>> 16), (byte) (l >>> 8), (byte) l };
    }
}

Related

  1. doubleToBytes(double d, byte[] data, int[] offset)
  2. doubleToBytes(double dnum, byte[] bytes, int startIndex)
  3. doubleToBytes(double v, byte[] bytes)
  4. doubleToBytes(double v, byte[] bytes, int off)
  5. doubleToBytes(double value)
  6. doubleToBytes(final double val)
  7. DoubleToBytes_With_Little_Endian(double number)
  8. putDouble(byte[] b, double val)
  9. putDouble(byte[] data, int i, boolean le, double v)