I am reading floating point values from a PLC's 32 bit memory area as (they would be) Integer values. How can I convert this Integer to Single in C#?

Viewed 44

enter image description hereI am reading values from a S7-300 PLC with my c# code. When the values are in INT format there is no problem. But there are some 32 bit memory areas (Double Words) that are encoded in IEEE 754 Floating-Point standart. (First bit is sign bit, the next 8 bits exponent, and the remaining 23 bits Mantissa) I can read out this memory areas from the PLC only as Int32 (As they were integer).

How can I convert this as integer read value to a single Real value in C# with respeect of the IEEE 754 Floating-Point encoding in the double word?

1 Answers

It worked just as wanted with Eldar's answer. If you read a 32 bit float value as bit, then just convert it like this: Thanks again to Eldar :-)

var finalSingle= BitConverter.ToSingle(BitConverter.GetBytes(s7Int))

Related