Java Byte Array to Double byteArrayToDoubleArray(final byte[] raw, final boolean bigEndian, final int length)

Here you can find the source of byteArrayToDoubleArray(final byte[] raw, final boolean bigEndian, final int length)

Description

byte Array To Double Array

License

Open Source License

Parameter

Parameter Description
raw a parameter
bigEndian a parameter
length a parameter

Declaration

public static double[] byteArrayToDoubleArray(final byte[] raw, final boolean bigEndian, final int length) 

Method Source Code

//package com.java2s;
/*/*w w  w . j av  a  2s.c om*/
 * Cross, common runtime object support system.
 * Copyright (C) 2008-2012, The authors of Cross. All rights reserved.
 *
 * Project website: http://maltcms.sf.net
 *
 * Cross may be used under the terms of either the
 *
 * GNU Lesser General Public License (LGPL)
 * http://www.gnu.org/licenses/lgpl.html
 *
 * or the
 *
 * Eclipse Public License (EPL)
 * http://www.eclipse.org/org/documents/epl-v10.php
 *
 * As a user/recipient of Cross, you may choose which license to receive the code
 * under. Certain files or entire directories may not be covered by this
 * dual license, but are subject to licenses compatible to both LGPL and EPL.
 * License exceptions are explicitly declared in all relevant files or in a
 * LICENSE file in the relevant directories.
 *
 * Cross is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. Please consult the relevant license documentation
 * for details.
 */

public class Main {
    /**
     *
     * @param raw
     * @param bigEndian
     * @param length
     * @return
     */
    public static double[] byteArrayToDoubleArray(final byte[] raw, final boolean bigEndian, final int length) {
        final double[] d = new double[length];
        int i = 0;
        if (bigEndian) {
            for (int iii = 0; iii < raw.length; iii += 8) {
                long ieee754 = 0;
                ieee754 |= ((raw[iii]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 1]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 2]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 3]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 4]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 5]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 6]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 7]) & 0xff);
                final double aDouble = Double.longBitsToDouble(ieee754);
                d[i++] = aDouble;
            }
        } else {
            for (int iii = 0; iii < raw.length; iii += 8) {
                long ieee754 = 0;
                ieee754 |= ((raw[iii + 7]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 6]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 5]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 4]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 3]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 2]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii + 1]) & 0xff);
                ieee754 <<= 8;
                ieee754 |= ((raw[iii]) & 0xff);
                final double aDouble = Double.longBitsToDouble(ieee754);
                d[i++] = aDouble;
            }
        }
        return d;
    }
}

Related

  1. byteArrayToDouble(byte high[], byte low[])
  2. byteArrayToDouble(byte[] b)
  3. byteArrayToDouble(byte[] byteArray)
  4. byteArrayToDouble(byte[] byteArray)
  5. byteArrayToDouble(byte[] bytes)
  6. byteArrayToDoubleBE(byte[] data)
  7. bytes2double(byte[] b)
  8. bytes2double(byte[] bytes)
  9. bytesToDouble(byte[] buffer)