1,105,263 Community Members

LoWord HiWord Vb.net Syntax

Unhnd_Exception
Deleted Member
 
2
 

Hopefully someone searches this one day and it becomes useful. I never found anything.

Below is the vb syntax for combining numbers in the same memory address.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim LngWord As Long = LngMakeWord(Integer.MaxValue, 65489)
    Dim LoLng As Integer = LngLoWord(LngWord)
    Dim HiLng As Integer = LngHiWord(LngWord)

    Dim IntWord As Integer = IntMakeWord(6536, 25548)
    Dim IntLo As Short = IntLoWord(IntWord)
    Dim IntHi As Short = IntHiWord(IntWord)

End Sub

Private Function IntMakeWord(ByVal loWord As Short, ByVal hiWord As Short) As Integer

    Return (CInt(hiWord) << 16) Or (CInt(loWord) And Short.MaxValue)

End Function

Private Function IntLoWord(ByVal word As Integer) As Short

    Return CShort(word And Short.MaxValue)

End Function

Private Function IntHiWord(ByVal word As Integer) As Short

    Return CShort((word >> 16))

End Function




Private Function LngMakeWord(ByVal loWord As Integer, ByVal hiWord As Integer) As Long

    Return CLng(hiWord) << 32 Or (CLng(loWord) And UInteger.MaxValue)

End Function

Private Function LngLoWord(ByVal word As Long) As Integer

    Return CInt(word And UInteger.MaxValue)

End Function

Private Function LngHiWord(ByVal word As Long) As Integer

    Return CInt(word >> 32)

End Function
Member Avatar
zinnqu
Junior Poster in Training
86 posts since Jun 2009
Reputation Points: 7 [?]
Q&As Helped to Solve: 15 [?]
Skill Endorsements: 0 [?]
 
0
 

Useful Thanks!

You
Post:
Start New Discussion
View similar articles that have also been tagged: