Java Byte Array to Float arr2float(byte[] b)

Here you can find the source of arr2float(byte[] b)

Description

arrfloat

License

Open Source License

Declaration

public static float arr2float(byte[] b) 

Method Source Code

//package com.java2s;
/*/*w  w  w  . j  av a2 s. co  m*/
#
# BinaryUtils.java
#
# copyright (c) 2009-2010, Danny Arends
# last modified Dec, 2010
# first written Dec, 2010
#
#     This program is free software; you can redistribute it and/or
#     modify it under the terms of the GNU General Public License,
#     version 3, as published by the Free Software Foundation.
# 
#     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, version 3, for more details.
# 
#     A copy of the GNU General Public License, version 3, is available
#     at http://www.r-project.org/Licenses/GPL-3
#
*/

public class Main {
    public static float arr2float(byte[] b) {
        int i = 0;
        int len = 4;
        int cnt = 0;
        byte[] tmp = new byte[len];
        for (i = 0; i < len; i++) {
            tmp[cnt] = b[i];
            cnt++;
        }
        int accum = 0;
        i = 0;
        for (int shiftBy = 0; shiftBy < 32; shiftBy += 8) {
            accum |= ((long) (tmp[i] & 0xff)) << shiftBy;
            i++;
        }
        return Float.intBitsToFloat(accum);
    }
}

Related

  1. byteArrayToFloat(byte value[])
  2. byteArrayToFloat(byte[] array)
  3. byteArrayToFloat(byte[] b)
  4. byteArrayToFloat(byte[] byteArray)