Here you can find the source of toFloat(byte[] data)
Parameter | Description |
---|---|
data | - the byte array |
public static float toFloat(byte[] data)
//package com.java2s; /**/*from www . j av a 2 s. 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 float * * @param data - the byte array * @return the float value */ public static float toFloat(byte[] data) { if (data == null || data.length != 4) return 0x0; return Float.intBitsToFloat(toInt(data)); } /** * Convert byte array to int * * @param data - the byte array * @return the int value */ public static int toInt(byte[] data) { if (data == null || data.length != 4) return 0x0; // @formatter:off return (int) ((0xff & data[0]) << 24 | (0xff & data[1]) << 16 | (0xff & data[2]) << 8 | (0xff & data[3]) << 0); // @formatter:on } }