Java Binary to Double bin2double(byte[] array, int offset)

Here you can find the source of bin2double(byte[] array, int offset)

Description

bindouble

License

Apache License

Declaration

public static double bin2double(byte[] array, int offset) 

Method Source Code

//package com.java2s;
/*//  w  w w.j  a  v  a 2s  .c o  m
 * Copyright (C) 2011 Alastair R. Beresford
 * Copyright (C) 2012 Daniel R. Thomas (drt24).
 *
 * 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 bin2double(byte[] array, int offset) {
        return Double.longBitsToDouble(bin2long(array, offset));
    }

    public static double bin2double(byte[] array) {
        return Double.longBitsToDouble(bin2long(array));
    }

    public static long bin2long(byte[] array, int offset) {
        return ((array[offset + 0] & 0xffL) << 56) + ((array[offset + 1] & 0xffL) << 48)
                + ((array[offset + 2] & 0xffL) << 40) + ((array[offset + 3] & 0xffL) << 32)
                + ((array[offset + 4] & 0xffL) << 24) + ((array[offset + 5] & 0xffL) << 16)
                + ((array[offset + 6] & 0xffL) << 8) + (array[offset + 7] & 0xffL);
    }

    public static long bin2long(byte[] array) {
        return bin2long(array, 0);
    }
}