Anyone know how to write a program for the process stated on the title?
I'm trying to hard code some Modbus process for my project.
Firstly, there will be a value of 9998 in decimal or 0x270E in hexadecimal
Next, i want to split the hexadecimal value of 0x270E into 0x27 and 0x0E (How to split???)
Lastly, i want to store the hexadecimal value of 0x27 and 0x0E into their own individual integer array.
if i have understood your question correctly, you can try the following:
(0x270E bit_and 0x00FF) will give you 0x000E
(0x270E bit_and 0xFF00) will give you 0x2700. divide this by 0x0100 or bit shift it right by the required amount. will give you 0x0027.
The tutorial I linked for unions uses a struct of 2 short integers for 1 long integer, just as I have done here with a short integer and a character.
I do realise that the sizes of the variable type names is variable though accross systems, that could be a possible issue but surely there's simple ways around that, I know that there's a header somewhere which you can find the number of bits for each type correct?
9.5 Unions [class.union]
1 In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time. [ Note: One special guarantee is made in order to simplify the use of unions: If a standard-layout union contains several standard-layout structs that share a common initial sequence (9.2), and if an object of this standard-layout union type contains one of the standard-layout structs, it is permitted to inspect the common initial sequence of any of standard-layout struct members; see 9.2. —end note ]