• Not Answered

Two 16Bit Word to a 32Bit Dword

Hi,

how can i convert two word to one dword?

Lars

3 Replies

  • Do you mean create a 32-bit unsigned integer with 16-bit integer A for bits 1-16 and 16-bit integer B for bits 17-32?

    Use a calc block to roll  16-bit Integer B by 16 bits (ROTL) then add it to integer A.  

    When doing calculations on these 16 and 32 bit integers, make sure to store all values to parameters of the proper data type to avoid precision loss caused by casting to the wrong data type, like floating point.

  • Also, keep in mind that that the extensible parameters (Inx and Outx) are Floating point (Real) data type. This means that you'll lose precision in your 32-bit integer. Try using external references from within the CALC expression so that they don't pass through the Floating Point type conversion of the Ins and Outs.
  • In reply to Brent Hamilton:

    create a 32 bit integer parameter and use a bitwise expression to convert the two 16 bit words to 32 bit:

    '^/32DWORD.CV' := ROTL('^/16DWORDA.CV',16) | '^/16DWORDB.CV';

    point is, as Brent mentions, don't pass values via IN and OUT connectors of CALC block.

    A bitwise OR command enforces 32 bit binary format. I'm not sure if using + would result in treating numbers as float. be sure to test with appropriately large values.

    Andre Dicaire