1) Dimension 24-bit variables.
2) Start with Most Significant Byte. Left-shift 16 times. This puts zeroes in rightmost 16 columns.
3) Take middle byte. Left-shift 8 times. This puts zeroes in rightmost 8 columns.
4) No need to alter Least Significant Byte.
5) Now add all three together.
I did not expect the OP (as a long term member) to ask this basic question.
It has been discussed with formulae, with mathematics, with code examples for decades and many million times. ... in basic coding documents.
Thus I´m not sure what to answer.
Code:
I mean bitwise it is:
* H-Byte: HHHHHHHH
* M-Byte: MMMMMMMM
* L-Byte: LLLLLLLL
so in total: HHHHHHHHMMMMMMMMLLLLLLLL
It hasn't been mentioned which numbers are handled by the MODBUS library, I guess at least 16-Bit quantities (registers) possibly even 32-Bit (double register).
I did not expect the OP (as a long term member) to ask this basic question.
It has been discussed with formulae, with mathematics, with code examples for decades and many million times. ... in basic coding documents.
Thus I´m not sure what to answer.
Code:
I mean bitwise it is:
* H-Byte: HHHHHHHH
* M-Byte: MMMMMMMM
* L-Byte: LLLLLLLL
so in total: HHHHHHHHMMMMMMMMLLLLLLLL
@KlausST Yes, you are right. There is a typo in my formula. Unfortunately, I cannot edit that message. The correct formula is:
H * 0x10000 + M * 0x100 + L
Still unclear what the OP is after.
Code? (Which language, which IDE, wich microcontroller)
Explanation --> should already be given
Math --> given
Sth else? --> don´t know