Java Float Number Create toFloat(byte[] data)

Here you can find the source of toFloat(byte[] data)

Description

Convert byte array to float

License

Open Source License

Parameter

Parameter Description
data - the byte array

Return

the float value

Declaration

public static float toFloat(byte[] data) 

Method Source Code

//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
    }
}

Related

  1. toFloat(byte[] bytes)
  2. toFloat(byte[] bytes)
  3. toFloat(byte[] bytes)
  4. toFloat(byte[] bytes, int index)
  5. toFloat(byte[] bytes, int offset)
  6. toFloat(byte[] data)
  7. toFloat(byte[] data, int offset)
  8. toFloat(byte[] si, boolean isReverseOrder)
  9. toFloat(byte[] value)