1.11M 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
 
0
 

Useful Thanks!

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This is an OP Kudos discussion and contributors may be rewarded
Post:
Start New Discussion
View similar articles that have also been tagged: