Here you can find the source of toDouble(byte[] data)
Parameter | Description |
---|---|
data | - the byte array |
public static double toDouble(byte[] data)
//package com.java2s; /**//from w w w.ja v a 2s . c o m * Syncnapsis Framework - Copyright (c) 2012-2014 ultimate * * 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 * 3 of the License, or 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 MECHANTABILITY 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 Plublic License along with this program; * if not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Convert byte array to double * * @param data - the byte array * @return the double value */ public static double toDouble(byte[] data) { if (data == null || data.length != 8) return 0x0; return Double.longBitsToDouble(toLong(data)); } /** * Convert byte array to long * * @param data - the byte array * @return the long value */ public static long toLong(byte[] data) { if (data == null || data.length != 8) return 0x0; // (Below) convert to longs before shift because digits are lost with ints beyond the 32-bit // limit // @formatter:off return (long) ((long) (0xff & data[0]) << 56 | (long) (0xff & data[1]) << 48 | (long) (0xff & data[2]) << 40 | (long) (0xff & data[3]) << 32 | (long) (0xff & data[4]) << 24 | (long) (0xff & data[5]) << 16 | (long) (0xff & data[6]) << 8 | (long) (0xff & data[7]) << 0); // @formatter:on } }