Results 1 to 5 of 5

Thread: What are "high order" and "low order" words?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    28

    What are "high order" and "low order" words?

    I ran into these terms when I started reading about API. Can you tell me what they mean? Please be as popular as you can with your explanation, I don't know many other terms when talking about API...

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    A long integer ("Long" in VB) takes up 32 bits of memory.
    An word ("integer" in VB6)takes up 16 bits

    This means that you can fit two words in the same space as would be taken by one long integer.

    The windows API uses this to pass two word parameters to a function that normally takes one long integer.

    To seperate this long integer into two words you take the first 16 bits into one word (the "high word") and the second 16 bits into the other word (the "low word").

  3. #3
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    Someplace 'ore the rainbow
    Posts
    392
    What would be the easiest way to separate these?

    cjqp
    When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.

  4. #4
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    VB Code:
    1. Option Explicit
    2.  
    3. '\\ Memory manipulation routines
    4. Private Declare Sub CopyMemoryByte Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, ByVal Source As Long, ByVal Length As Long)
    5. Private Declare Sub CopyMemoryWord Lib "kernel32" Alias "RtlMoveMemory" (Destination As Integer, ByVal Source As Long, ByVal Length As Long)
    6.  
    7.  
    8. Public Function HiByte(ByVal w As Integer) As Byte
    9.  
    10.     Call CopyMemoryByte(HiByte, VarPtr(w) + 1, 1)
    11.    
    12. End Function
    13.  
    14. Public Function LoByte(w As Integer) As Byte
    15.  
    16.     Call CopyMemoryByte(LoByte, VarPtr(w), 1)
    17.    
    18. End Function
    19.  
    20. Public Function LoWord(dw As Long) As Integer
    21.  
    22. Call CopyMemoryWord(LoWord, VarPtr(dw), 2)
    23.  
    24. End Function
    25.  
    26. Public Function HiWord(dw As Long) As Integer
    27.  
    28. Call CopyMemoryWord(HiWord, VarPtr(dw) + 2, 2)
    29.  
    30. End Function
    Last edited by Merrion; Sep 22nd, 2004 at 09:39 AM.

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim TestVal As Long, HighInt As Integer, LowInt As Integer
    3.     TestVal = &HF000F000
    4.     'check if the highest bit is active (because Longs are signed)
    5.     If (TestVal And &H80000000) = &H80000000 Then
    6.         'rip 15 bits after the highest bit and activate the highest bit
    7.         HighInt = ((TestVal And &H7FFF0000) \ &H10000) Or &H8000
    8.     Else
    9.         'rip 15 bits after the highest bit
    10.         HighInt = (TestVal And &H7FFF0000) \ &H10000
    11.     End If
    12.     'rip lower 16 bits
    13.     LowInt = TestVal Mod &H10000
    14.     'view results
    15.     Debug.Print HighInt, LowInt
    16. End Sub

    You can test what happens when you change TestVal and change HighInt and LowInt to Long datatype.


    Edit Please note doing this without API and/or assigning into a function is far faster than with API or by making a function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width