An implausible instrument-register value may result from byte order or numerical encoding. The example uses a 32-bit float carried in two Modbus registers: first check the manufacturer’s stated format, then compare the raw bytes with the expected value.
The case
A typical chain: a meter exposes a reading over Modbus, two consecutive 16-bit registers that together form a 32-bit float. Our side reads the registers, concatenates them, interprets them as float, and prints a number with no physical meaning. It helps to drop down to the single-byte level and ask two distinct questions: in what order do the bytes arrive, and how do those bytes encode a number. These are two independent problems, and when the values read are implausible, rule out byte order before questioning the encoding.
Endianness: the same number, bytes in a different order
A 32-bit integer or float is four bytes. Endianness is the convention for which byte comes first in memory or on the wire. Big-endian puts the most significant byte (MSB) first, in the order we’d write the number by hand; little-endian puts the least significant (LSB) first. The four bytes 41 BD 70 A4 interpreted big-endian are 23.68; the same bytes read little-endian, i.e. A4 70 BD 41, are a completely different and meaningless float.
Modbus complicates things because it works in big-endian 16-bit registers, but doesn’t specify the order between the two registers of a 32-bit float. So in practice up to four variants arise — ABCD, CDAB, BADC, DCBA — depending on whether the vendor swaps bytes, words, both, or neither (the notorious word swap). The datasheet, if well written, tells you which; if badly written, you find out by hand. That’s why, faced with absurd numbers, the first move is to systematically try the four byte orders: if one of the permutations returns the expected value, the problem was endianness and not decoding.
IEEE 754: how bytes become a number
IEEE 754 binary32 has 1 sign bit, 8 exponent bits with bias 127 and 23 fraction bits. For a normal number the value is (-1)^sign × (1 + fraction/2^23) × 2^(exponent−127). The implicit-1 formula does not apply to every pattern: exponent 0 identifies zeros or subnormals; exponent 255 identifies infinity if the fraction is zero and NaN otherwise. An instrument may use NaN for an invalid measurement: it does not alone prove incorrect byte order. Check format, alignment and field meaning in the manufacturer’s protocol.
For integers the twin trap is the sign. Negative values are encoded in two’s complement: invert all the bits and add 1. Reading a 16-bit register as unsigned when the instrument intends it signed makes a -3 show up as 65533 — again an “absurd” number that is really just interpreted with the wrong convention. And as with floats, on a multi-register value the byte order must be resolved before applying two’s complement.
Verification method
Compare raw bytes, declared byte order and encoding before interpreting the physical meaning of a result. A plausible permutation is evidence to confirm against documentation and several known values. The Altera IEEE 754 format documentation distinguishes normal numbers and special cases.
To inspect any four bytes by hand across the different orders and encodings we put a Data Format Inspector online; the detail on endianness, IEEE 754 and two’s complement is in the dedicated wiki.
For instrument integration over Modbus, serial or binary protocols, send us the format and interface requirements.