Sign in to follow this  
Followers 0
Guest Guest_Mike

Dword to 2 words and back

3 posts in this topic

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0