32 bits dint to two 16bits dint
I need split a 32bit dint number in two 16bits dint, for send it by modbus tcp. There is a block to do that?
Thanks
Answers
Which controller you are asking about ?
There should be a converter function block.
At least you can convert integer long to 32 bit binary and each 16 bits to integer.
How is the remote PLC going to "reassemble" the two 16 bit words ? You can run into problems with 2's complement binary numbers ( ie negative values ) doing things like this. Anyway ...
dint = 32 bits , int = 16 bits
Basically you shouldnt really need to do anything, just send a dint. The receiving end can deal with the 4 bytes of data as 2 * ints. Otherwise you can use...
DWORD := dint_to_dword(DINT); // convert to 32 Bit Dword so you can use binary logic
LowBytes := DWORD AND #16FF; // Bitwise "and" to mask the lower 16 bits
HighBytes := ROL(DWORD,16) AND #16FF; // Rotate Left 16 bits to move high bytes to low bytes
Where HighBytes and LowBytes are declared as "int"
Add new comment