EasyManua.ls Logo

Siemens SIMATIC IOT - Converting Real to Float

Siemens SIMATIC IOT
133 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Maintaining and repairing the device
6.6 Configure IOT2050 SM
SIMATIC IOT2050
84 Operating Instructions, 03/2024, A5E39456816-AF
printf("Test failed: dq0 != di0\r\n");
break;
}
printf("Test ok\r\n");
}
close(dq0);
close(di0);
return ret;
}
6.6.2.3 Converting real to float
If the raw value of the module contains real type, convert these values to a float data type.
The following examples show converting real to float with C and Python.
Example: converts real to float with C
/**
* @brief Convert IEEE754 floating point.
*/
double real_to_float(uint32_t real)
{
int sign = real >> 31;
int exponent = ((real >> 23) & 0xFF) - 127;
uint32_t mantissa = real & 0x7FFFFF;
int power_count = -1;
double mantissa_int = 0;
for (int i = 0; i < 23; i++) {
mantissa_int += ((mantissa >> (22 - i)) & 1) * pow(2,
power_count);

Table of Contents

Other manuals for Siemens SIMATIC IOT

Related product manuals