Jump to content

Dword to 2 words and back


Recommended Posts

Guest Guest_Mike
Posted
I got to fetch and poke data to an FX2n PLC. I'm getting 32 bit register data that I get in terms of 2 signed words (lsw and msw) that I need to put back together as a Dword. I also need to take a Dword and figure out the 2 words that make it and send back to the PLC. It's MX Component and VB6. I got a formula but it does not work if the msw is a negative integer? Any ideas? I need to do the conversion in VB6. Thanks, Mike

Posted
I'm not sure I understand it correctly but it should be just a simple bit manipulation like this: Public Function ConvertToDINT(intA As Integer, intB As Integer) As Long Dim intC As Long    If intA < 0 Then intC = 32768    intA = intA And &H7FFF    intC = CLng(intB) * (2 ^ 16) + intC + intA    ConvertToDINT = intC End Function This should combine two 16-bit integers into DINT. Just do the same steps backwards to convert DINT into two INTs.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...