Jump to content

Recommended Posts

Posted (edited)

These functions store and retrieve 16 bit values in/from a 32 bit value.

; ===================================================================
; _MakeLong($a, $b)
;
; Concatenates two 16 bit values into one 32 bit value.
; Parameters:
;    $l - IN - The low order word (Lowest 16 bits)
;    $h - IN - The high order word (Highest 16 bits)
; Returns:
;    The two 16 bit values concatenated into a single 32 bit value.
; Notes:
;    Retrieve the values with HiWord and LoWord respectively.
; ===================================================================
Func _MakeLong($l, $h)
    Return BitOR(BitAnd($l, 0xFFFF), BitShift(BitAnd($h, 0xFFFF), -16))
EndFunc  ; _MakeLong()

; ===================================================================
; _HiWord($x)
;
; Retrieves the high-order word from the 32 bit argument.
; Parameters:
;    $x - IN - A 32 bit argument created with  _MakeLong()
; Returns:
;    The highest 16 bits from the 32 bit integer.
; ===================================================================
Func _HiWord(ByRef $x)
    Return BitShift($x, 16)
EndFunc  ; _HiWord()

; ===================================================================
; _LoWord($x)
;
; Retrieves the low-oder word from the 32 bit argument
; Parameters:
;    $x - IN - A 32 bit argumented created with _MakeLong()
; Returns:
;    The lowest 16 bits from the 32 bit integer.
; ===================================================================
Func _LoWord(ByRef $x)
    Return BitAnd($x, 0xFFFF)
EndFunc  ; _LoWord()

Can be tested with:

Local $a = _MakeLong(100, 200)
MsgBox(4096, "High", _HiWord($a))
MsgBox(4096, "Low", _LoWord($a))

Edit: Added ByRef to _HiWord()/_LoWord() to help make sure the correct parameter is passed (Meaning, a literal string can't be passed by somebody incorrectly using those functions).

Edited by Valik

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...