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

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

Description

byte Array To Double

License

Open Source License

Declaration

public static double byteArrayToDouble(byte[] b) 

Method Source Code

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

public class Main {
    public static double byteArrayToDouble(byte[] b) {
        long l = byteArrayToLong(b);
        return Double.longBitsToDouble(l);
    }/*  w  w  w  .jav  a 2s .c  o  m*/

    public static long byteArrayToLong(byte[] b) {
        //8 16 24 32 40 48 56 ..
        return ((long) byteAt(b, 0) << 56) + ((long) (byteAt(b, 1) & 0xFF) << 48)
                + ((long) (byteAt(b, 2) & 0xFF) << 40) + ((long) (byteAt(b, 3) & 0xFF) << 32)
                + ((long) (byteAt(b, 4) & 0xFF) << 24) + ((long) (byteAt(b, 5) & 0xFF) << 16)
                + ((long) (byteAt(b, 6) & 0xFF) << 8) + ((long) byteAt(b, 7) & 0xFF);

    }

    private static byte byteAt(byte[] b, int p) {
        if (b != null && p < b.length)
            return b[p];
        return 0;
    }
}

Related

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