Main Site Documentation

Help me to convert 4 byte To Float


#1

hollow,
I want convert 4 byte to float en C#
Help me please

///////////////////////////
using System;
using Microsoft.SPOT;
using GHI.Premium.System;
public class Program
{
unsafe public static void Main()
{
byte[] data = new byte[4];
float real;
//array, serialize
data[0] = 0;
data[1] = 0;
data[2] = 63;
data[3] = 128;
// I want convert 4 byte to float number
float h =(float) (data); ///

    }

}


#2

@ riad1986 - Is the byte array an ascii representation of a number or a serialized float?


#3

You can use
Microsoft.SPOT.Hardware.Utility.ExtractValueFromArray
and
Microsoft.SPOT.Hardware.Utility.InsertValueIntoArray
for other direction.


#4

Here’s mine:


public static float ToFloat(byte[] val,int index)
        {
            float ret;
            GHI.Premium.System.Util.ExtractValueFromArray(out ret,val,index);
            return ret;
        }


#5

thank you so much for the help :clap: