Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

How to concatenate Two 2-byte registers ?

Modbus Register 1  -   value1 (16 bits in length, contains bits 0 to 15)
Modbus Register 2  -   value2 (16 bits in length, contains bits 16 to 31)

short response_buffer[128];   // contains modbus register values

response_buffer[0] contains value1.  response_buffer[1] contains value2.

long result;

/* Is this solution correct ? */
result = (  (long)  ( response_buffer[0] ) +  (long) (response_buffer[1] << 16) ) ;

/* if above solution is correct, can it be simplified ? */
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial