How floating-point numbers are stored in the MODBUS RTU protocol, and how the values of the floating-point registers are converted to the required floating-point numbers

Source: Internet
Author: User

Floating-point numbers are saved in the following byte format:

Address +0 +1 +2 +3
Content seee eeee emmm MMMM MMMM MMMM MMMM MMMM

Over here
S represents the sign bit, 1 is negative, 0 is positive
The power of E offset 127, binary order = (EEEEEEEE)-127.
The mantissa of the M 24 bits is stored in 23 bits, with only 23 bits, and the highest bit fixed at 1. This method is implemented with the least number of bits
High number of significant digits, improving the accuracy.

0 is a specific value, the power is 0 Mantissa is also 0.

Floating-point number-12.5 as a hexadecimal number 0xc1480000 is saved in the store, and this value is as follows:
Address +0 +1 +2 +3
Content 0xc1 0x48 0x00 0x00

The conversion between floating-point numbers and hexadecimal equivalent saved values is fairly straightforward. The following example shows the above value-12.5 how to go
Change.
The floating-point save value is not a direct format, to be converted to a floating-point number, the bit must be saved in the format table by the floating-point numbers above
Separate from the list, for example:

Address +0 +1 +2 +3
Format seee eeee emmm MMMM MMMM MMMM MMMM MMMM
Binary 11000001 01001000 00000000 00000000
Hex C1 48 00 00

From this example, you can get the following information:
The sign bit is 1 to indicate a negative number
A power is a binary 10000010 or a decimal 130,130 minus 127 is 3, which is the actual power.
The mantissa is the binary number after 10010000000000000000000

On the left side of the mantissa there is an omitted decimal point and 1, this 1 is often omitted in the preservation of floating-point numbers, plus a 1 and a decimal
Point to the beginning of the mantissa to get the tail value as follows:
1.10010000000000000000000

Next, the mantissa is adjusted according to the exponent. A negative exponent moves the decimal point to the left. A positive exponent moves the decimal point to the right. because
The index is 3 and the mantissa is adjusted as follows:
1100.10000000000000000000

The result is a binary floating-point number, and the binary to the left of the decimal point represents the power of 2 of the position, for example: 1100 indicates
(1*2^3) + (1*2^2) + (0*2^1) + (0*2^0) = 12.
The right side of the decimal point also represents the power of 2 of the position, but the power is negative. For example:. 100 ... Representation (1*2^ (-1)) +
(0*2^ (-2)) + (0*2^ (-2)) ... =0.5.
The and of these values is 12.5. Because the sign bit is set to indicate that the number is negative, the hexadecimal value 0xc1480000 is represented-
12.5.

How floating-point numbers are stored in the MODBUS RTU protocol, and how the values of the floating-point registers are converted to the required floating-point numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.