Java Double Array Convert doubleArrayToBytes(double[] d)

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

Description

double Array To Bytes

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

public class Main {
    public static byte[] doubleArrayToBytes(double[] d) {
        byte[] r = new byte[d.length * 8];
        for (int i = 0; i < d.length; i++) {
            byte[] s = doubleToBytes(d[i]);
            for (int j = 0; j < 8; j++)
                r[8 * i + j] = s[j];//from  ww w . j  a  v  a  2  s. c  o  m
        }
        return r;
    }

    public static byte[] doubleToBytes(double d) {
        long l = Double.doubleToRawLongBits(d);
        byte[] r = new byte[8];
        for (int i = 0; i < 8; i++) {
            r[i] = (byte) ((l >>> (i * 8)) & 0xFF);
        }
        return r;
    }
}

Related

  1. doubleArrayToClassNames(int[] labels, String[] classNames, Character separatorChar)
  2. doubleArrayToFloatArray(double[] doubleArray)
  3. doubleArrayToIntArray(double[] doubles)