Java Byte Array to Double byteArrayToDouble(byte[] byteArray)

Here you can find the source of byteArrayToDouble(byte[] byteArray)

Description

byte array to double

License

Apache License

Parameter

Parameter Description
byteArray a parameter

Return

double

Declaration

public static double byteArrayToDouble(byte[] byteArray) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  w  w w  . ja  v a  2s  .c om*/
     * byte array to double
     * 
     * @param byteArray
     * @return double
     */
    public static double byteArrayToDouble(byte[] byteArray) {
        double number = 0d;
        if (byteArray != null && byteArray.length == 8) {
            long longBits = 0l;
            longBits = byteArray[0];
            longBits &= 0xff;
            longBits |= ((long) byteArray[1] << 8);
            longBits &= 0xffff;
            longBits |= ((long) byteArray[2] << 16);
            longBits &= 0xffffff;
            longBits |= ((long) byteArray[3] << 24);
            longBits &= 0xffffffffl;
            longBits |= ((long) byteArray[4] << 32);
            longBits &= 0xffffffffffl;
            longBits |= ((long) byteArray[5] << 40);
            longBits &= 0xffffffffffffl;
            longBits |= ((long) byteArray[6] << 48);
            longBits &= 0xffffffffffffffl;
            longBits |= ((long) byteArray[7] << 56);
            number = Double.longBitsToDouble(longBits);
        }
        return number;
    }
}

Related

  1. arr2double(byte[] b)
  2. byteArrayToDouble(byte high[], byte low[])
  3. byteArrayToDouble(byte[] b)
  4. byteArrayToDouble(byte[] byteArray)
  5. byteArrayToDouble(byte[] bytes)
  6. byteArrayToDoubleArray(final byte[] raw, final boolean bigEndian, final int length)
  7. byteArrayToDoubleBE(byte[] data)