We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,668 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

LoWord HiWord Vb.net Syntax

Jan 20th, 2011 5:09 am

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

Useful Thanks!

zinnqu
Junior Poster in Training
86 posts since Jun 2009
Reputation Points: 21
Solved Threads: 15
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0565 seconds using 2.67MB