Why 32-bit values look wrong - and how to fix them
Tutorials › Float32 & Byte Order
A Modbus register is only 16 bits. To carry a 32-bit value - a Float32 (IEEE 754) temperature, a UInt32 counter, an Int32 measurement - a device uses two consecutive registers. The catch is that vendors do not agree on the order of those bytes, which is why a reading that should say 123.45 sometimes shows up as a huge nonsense number.
Call the four bytes of the 32-bit value A B C D (A is the most significant byte). They are packed into two registers, but the order can be swapped at the word level and at the byte level. The four common combinations are:
| Order | Register 1 | Register 2 | Also called |
|---|---|---|---|
| ABCD | A B | C D | Big-endian |
| DCBA | D C | B A | Little-endian |
| BADC | B A | D C | Big-endian, byte swap |
| CDAB | C D | A B | Word swap (common on Siemens) |
Suppose the value 123.45 (hex 0x42F6E666) is stored as bytes A=42, B=F6, C=E6, D=66. A device using ABCD sends register 1 = 0x42F6 and register 2 = 0xE666. A device using CDAB sends register 1 = 0xE666 and register 2 = 0x42F6. Same value, swapped words - if your tool assumes the wrong order, the float is garbage.
Some devices store a value as a scaled 16-bit integer instead of a float - for example raw 1234 meaning 123.4 °C (scale 0.1). If a "float" still looks off after trying every byte order, check the device manual for a scale factor.
ModbusBB lets you switch a register's format to Float32/Int32/UInt32 and cycle byte order (ABCD/DCBA/BADC/CDAB) per register - so you can find the right interpretation in seconds. Its simulator can also serve 32-bit values in any byte order for testing. Download the free trial.
Next: what Modbus exception codes mean and how to fix them.