Appendix A. Floating point representation
- Last UpdatedNov 17, 2022
- 2 minute read
The manner in which PLCs store floating-point numbers vary. As a result, the Modbus commands that are needed to retrieve floating point values will also vary from PLC to PLC. The user can specify the manner in which the PLC stores a floating point with the data type parameter that is discussed under Point Definition earlier in this manual.
Note: Standard 4-byte IEEE floating points on Intel Windows are represented as follows:
byte 3: S MSBE E E E E E E
byte 2: LSBE MSBF F F F F F F
byte 1: F F F F F F F F
byte 0: F F F F F F F LSBF
where,
S = sign bit (1 = -)
MSBE = most significant bit exponent
LSBE = least significant bit exponent
MSBF = most significant bit fraction
LSBF = least significant bit fraction
For example, the number 1 is stored as a floating-point number by:
byte 0 = 0 byte 1 = 0 byte 2 = 0x80 byte 3 = 0x3f
where 0x80 and 0x3f are hexadecimal numbers.
All four-byte floating-point values will be returned in two registers. For purposes of discussion, the low-order register will contain bytes 0 and 1, and the "high-order register" will contain bytes 2 and 3. This definition is somewhat arbitrary because there is no good reason to consider byte 3 (the byte with the exponent) of higher order than byte 1 or byte 0 (bytes containing the fraction).
Some PLCs will send the low register back first and then the high register, while other PLCs will send the high register back first and then the low register. The order in which the ModbusE interface expect the bytes is different for each data type (see below).
The interface currently supports 3 different methods of reading and writing IEEE floating point numbers. Data types 4, 5 and 6 (defined in the Location3) are IEEE floating points.
The interface can also read Siemens type floating point values (data type 8), but writes of Siemens floats are not supported. 4-byte integers (data type 7) are also discussed below.