Followers 0

# Floating point aritmetics

## 3 posts in this topic

Hi, I read a measurement from a device via serial port, and I get the value as a 32bit unsigned binary number: bits 31...24 Decade exponent (signed 8 bit) bits 23...00 Binary unsigned value (24 bit) Example: 123456*10E-3 is stored as FD01 E240 (hex) So I have to convert the 32bit unsigned value to float To do this I plan to implement the folowing algorithm: 1. Extract the exponent value from the 32bit (bits 31..24) Extracted exponent would be stored as 32bit signed value 2. Convert the exponent to float using FLTL(453) instruction. It converts 32bit value to float. 3. 10 Power Exponent with PWR(840) instruction 4. Extract the base from the 32bit (bits 23..00) 5. Convert the Base to Float using FLTL(453) instruction 6. Multiply the Base with the value calculated in step 3, using *F(456) instruction I have to do the same conversion with a 32 bit signed value. The Value format is the ame as above. Is there any shorer/easier/more elegant solution? Thanks in advance chombium

##### Share on other sites
1 How about multipying the float by 10000 using *F? Then convert to Fixed by FIXL. Take that result and split between two locations - one for integer and one for four places of decimal. 2. Depending on what you need the float for, how about converting the float to ASCII using FSTR?

##### Share on other sites
That option didn't cross my mind The thing is that I need to read the value from the PLC using SCADA system created in Wonderware. The thing that you suggest seems quite resonable: I'll have the integer and the decimal part in two words so I could add the decimal point between those two values when presenting on the SCADA screen Thanks, Jay chombium