Java Byte Array to Double byteToDouble(byte[] bytes)

Here you can find the source of byteToDouble(byte[] bytes)

Description

Converts an array of bytes into a double Byte order: big endian

License

Open Source License

Parameter

Parameter Description
bytes an array of double

Return

the corresponding float

Declaration

public static double byteToDouble(byte[] bytes) 

Method Source Code

//package com.java2s;
/**/*from w ww.j a v  a 2  s.  c  o m*/
 * OrbisGIS is a GIS application dedicated to scientific spatial simulation.
 * This cross-platform GIS is developed at French IRSTV institute and is able to
 * manipulate and create vector and raster spatial information.
 *
 * OrbisGIS is distributed under GPL 3 license. It is produced by the "Atelier SIG"
 * team of the IRSTV Institute <http://www.irstv.fr/> CNRS FR 2488.
 *
 * Copyright (C) 2007-2012 IRSTV (FR CNRS 2488)
 *
 * This file is part of OrbisGIS.
 *
 * OrbisGIS is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * OrbisGIS 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. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * OrbisGIS. If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, please consult: <http://www.orbisgis.org/>
 * or contact directly:
 * info_at_ orbisgis.org
 */

public class Main {
    private static final int BYTESIZE = 0xFF;

    /**
     * Converts an array of bytes into a double
     * 
     * Byte order: big endian
     * 
     * @param bytes an array of double
     * @return the corresponding float
     */
    public static double byteToDouble(byte[] bytes) {
        return Double.longBitsToDouble(bytesToLong(bytes));
    }

    /**
     * Converts an array of bytes into a long
     * 
     * Byte order: big endian
     * 
     * @param bytes an array of bytes
     * @return the corresponding long
     */
    public static long bytesToLong(byte[] bytes) {
        return (((long) bytes[0] << 56) + ((long) (bytes[1] & BYTESIZE) << 48)
                + ((long) (bytes[2] & BYTESIZE) << 40) + ((long) (bytes[3] & BYTESIZE) << 32)
                + ((long) (bytes[4] & BYTESIZE) << 24) + ((bytes[5] & BYTESIZE) << 16)
                + ((bytes[6] & BYTESIZE) << 8) + ((bytes[7] & BYTESIZE)));
    }
}

Related

  1. bytesToDouble(byte[] bytes, int startIndex)
  2. bytesToDouble(byte[] data, int[] offset)
  3. bytesToDouble(final byte[] bytes)
  4. bytesToDoubles(byte[] b)
  5. byteToDouble(byte[] b)
  6. byteToDouble(byte[] paramArrayOfByte)
  7. byteToDoubleArray(byte[] ar)