Java Byte Array to Double byteArrayToDouble(byte high[], byte low[])

Here you can find the source of byteArrayToDouble(byte high[], byte low[])

Description

byte Array To Double

License

Apache License

Declaration

public static double byteArrayToDouble(byte high[], byte low[]) 

Method Source Code

//package com.java2s;
/*//from www. j  a  va 2  s. c o m
 * Copyright 2004,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static double byteArrayToDouble(byte high[], byte low[]) {
        double temp = 0;
        // high bytes
        temp += (((long) high[0]) & 0xFF) << 56;
        temp += (((long) high[1]) & 0xFF) << 48;
        temp += (((long) high[2]) & 0xFF) << 40;
        temp += (((long) high[3]) & 0xFF) << 32;
        // low bytes
        temp += (((long) low[0]) & 0xFF) << 24;
        temp += (((long) low[1]) & 0xFF) << 16;
        temp += (((long) low[2]) & 0xFF) << 8;
        temp += (((long) low[3]) & 0xFF);
        return temp;
    }

    public static double byteArrayToDouble(byte value[]) {
        byte high[] = new byte[4];
        byte low[] = new byte[4];
        high[0] = value[0];
        high[1] = value[1];
        high[2] = value[2];
        high[3] = value[3];
        low[0] = value[4];
        low[1] = value[5];
        low[2] = value[6];
        low[3] = value[7];
        return byteArrayToDouble(high, low);
    }
}

Related

  1. arr2double(byte[] b)
  2. byteArrayToDouble(byte[] b)
  3. byteArrayToDouble(byte[] byteArray)
  4. byteArrayToDouble(byte[] byteArray)
  5. byteArrayToDouble(byte[] bytes)