Java Double Convert to double2Arr(double var, byte[] arrayBytes, int startIndex)

Here you can find the source of double2Arr(double var, byte[] arrayBytes, int startIndex)

Description

Write the bytes of "var" into new byte array.

License

Open Source License

Parameter

Parameter Description
var the double of 8 bytes to encode return tmp The byte array.

Declaration

public static void double2Arr(double var, byte[] arrayBytes, int startIndex) 

Method Source Code

//package com.java2s;
/* DielmoOpenLiDAR/*from   ww  w.j  a  v  a2  s  . co m*/
 *
 * Copyright (C) 2008 DIELMO 3D S.L. (DIELMO) and Infrastructures  
 * and Transports Department of the Valencian Government (CIT)
 * 
 * This program 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 2
 * of the License, or (at your option) any later version.
 * 
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * For more information, contact:
 *
 * DIELMO 3D S.L.
 * Plaza Vicente Andr?s Estell?s 1 Bajo E
 * 46950 Xirivella, Valencia
 * SPAIN
 *   
 * +34 963137212
 * dielmo@dielmo.com
 * www.dielmo.com
 * 
 * or
 * 
 * Generalitat Valenciana
 * Conselleria d'Infraestructures i Transport
 * Av. Blasco Ib??ez, 50
 * 46010 VALENCIA
 * SPAIN
 *
 * +34 963862235
 * gvsig@gva.es
 * www.gvsig.gva.es
 */

public class Main {
    /**
     * Write the bytes of "var" into new byte array.
     *
     * @param var the double of 8 bytes to encode
     * return tmp The byte array.
     */
    public static void double2Arr(double var, byte[] arrayBytes, int startIndex) {

        long bits = Double.doubleToLongBits(var);
        long2Arr(bits, arrayBytes, startIndex);
    }

    /**
     * Write the bytes of "var" into new byte array.
     *
     * @param var the long of 8 bytes to encode
     * return tmp The byte array to store into.
     */
    public static void long2Arr(long var, byte[] arrayBytes, int startIndex) {

        int length = 8;

        if (arrayBytes != null && startIndex + length <= arrayBytes.length) {
            for (int j = startIndex; j < startIndex + length; j++) {
                arrayBytes[j] = (byte) var; // se copian los 8 primeros bits de la variable
                var >>= 8;
            }
        }
    }
}

Related

  1. convertDoubleToFloat(final double[][] doubleSeries)
  2. convertDoubleToLong(Double value)
  3. convertDoubleToPercentage(double doub)
  4. convertDoubleToShort(double value)
  5. convertDoubleValuesFromNetcdf(double[] netcdfData, double missingValue, double scaleFactor, double offSet)
  6. double2array(int sz, double seed)
  7. double2bin(double d)
  8. double2bipolar(final double d[])
  9. double2dimToFloat1Dim(double[][] points)