Java Double Array Create toDoubleA(byte[] data)

Here you can find the source of toDoubleA(byte[] data)

Description

to Double A

License

Open Source License

Declaration

public static double[] toDoubleA(byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double[] toDoubleA(byte[] data) {
        if (data == null)
            return null;
        // ----------
        if (data.length % 8 != 0)
            return null;
        double[] dbls = new double[data.length / 8];
        for (int i = 0; i < dbls.length; i++) {
            dbls[i] = toDouble(new byte[] { data[(i * 8)],
                    data[(i * 8) + 1], data[(i * 8) + 2],
                    data[(i * 8) + 3], data[(i * 8) + 4],
                    data[(i * 8) + 5], data[(i * 8) + 6],
                    data[(i * 8) + 7], });
        }//from   w  w  w. j av  a  2 s . c o m
        return dbls;
    }

    public static double toDouble(byte[] data) {
        if (data == null || data.length != 8)
            return 0x0;
        // ---------- simple:
        return Double.longBitsToDouble(toLong(data));
    }

    public static long toLong(byte[] data) {
        if (data == null || data.length != 8)
            return 0x0;
        // ----------
        return (long) (
        // (Below) convert to longs before shift because digits
        //         are lost with ints beyond the 32-bit limit
        (long) (0xff & data[0]) << 56 | (long) (0xff & data[1]) << 48
                | (long) (0xff & data[2]) << 40
                | (long) (0xff & data[3]) << 32
                | (long) (0xff & data[4]) << 24
                | (long) (0xff & data[5]) << 16
                | (long) (0xff & data[6]) << 8 | (long) (0xff & data[7]) << 0);
    }
}

Related

  1. doubleArray(String data)
  2. doubleArray2Json(double[] array)
  3. doubleArrayFromString(final String data)
  4. doubleArrayFromString(String record)
  5. doubleArraySize(byte[] array)
  6. toDoubleArr(short[] arr)
  7. toDoubleArray(boolean[] array)
  8. toDoubleArray(byte[] byteArray)
  9. toDoubleArray(byte[] data)