17
Data format in instrument
Overview
Floating Point
Definition: Floating point, conforming to IEEE 754 (single precision)
Figure 14: floating point single-precision definition (4 bytes, 2 MODBUS registers)
Example: Compile decimal 17.625 to binary
Step 1: Converting 17.625 in decimal form to a floating-point number in binary form, first finding the
binary representation of the integer part
17decimal= 16 + 1 = 1×2
4
+ 0×2
3
+ 0×2
2
+ 0×2
1
+ 1×2
0
The binary representation of integer part 17 is 10001B
then the binary representation of decimal part is obtained
0.625= 0.5 + 0.125 = 1×2
−
1
+ 0×2
−
2
+ 1×2
−
3
The binary representation of decimal part 0.625 is 0.101B.
So the binary floating point number of 17.625 in decimal form is 10001.101B
Step 2: Shift to find the exponent.
Move 10001.101B to the left until there is only one decimal point, resulting in 1.0001101B, and
10001.101B = 1.0001101 B× 24 . So the exponential part is 4, plus 127, it becomes 131, and its binary
representation is 10000011B.
Step 3: Calculate the tail number
After removing 1 before the decimal point of 1.0001101B, the final number is 0001101B (because
before the decimal point must be 1, so IEEE stipulates that only the decimal point behind can be
recorded). For the important explanation of 23-bit mantissa, the first (i.e. hidden bit) is not compiled.
Hidden bits are bits on the left side of the separator, which are usually set to 1 and suppressed.
Step 4: Symbol bit definition
The sign bit of positive number is 0, and the sign bit of negative number is 1, so the sign bit of 17.625 is 0.
Step 5: Convert to floating point number
1 bit 8 bit index + 23-bit mantissa
0 10000011 00011010000000000000000B (the hexadecimal system is shown as
0 x418d0000 )
Reference code:
1. If the compiler used by the user has a library function that implements this function, the library
function can be called directly, for example, using
C language, then you can directly call the C library function memcpy to obtain an integer
representation of the floating-point storage format in memory.
For example: float floatdata; // converted floating point number
void* outdata; memcpy(outdata,&floatdata,4);
Suppose floatdata = 17.625
If it is a small-end storage mode, after executing the above statement,
the data stored in the address unit outdata is 0x00.
O 1 stores data as 0x00
address unit (o 2) stores data as 0x8D
address unit (o 3) stores data as 0x41
Description
Bit
Index Deviation
Symbol
3
Index
30…23
Mantissa
22…0
SUM
22…0
127