Java Double Array to Byte Array doublesToBytes(double[] d)

Here you can find the source of doublesToBytes(double[] d)

Description

doubles To Bytes

License

Open Source License

Declaration

public static byte[] doublesToBytes(double[] d) 

Method Source Code

//package com.java2s;
/** Ben F Rayfield offers this software opensource MIT license */

public class Main {
    public static byte[] doublesToBytes(double[] d) {
        byte[] b = new byte[d.length << 3];
        for (int i = 0; i < d.length; i++) {
            copyLongIntoByteArray(b, i << 3, Double.doubleToRawLongBits(d[i]));
        }/*from  ww w . jav  a  2  s.c om*/
        return b;
    }

    public static void copyLongIntoByteArray(byte[] b, int byteIndex, long j) {
        for (int i = 7; i >= 0; i--) {
            b[byteIndex + i] = (byte) j;
            j >>= 8;
        }
    }
}

Related

  1. doublesToBytes(double[] doubles)
  2. doublesToBytes(final double[] array)