HIWORD Macro

Public Function HIWORD (ByVal dwValue As Long) As Long
	Dim hexstr As String
	hexstr = Right("00000000" & Hex(dwValue), 8)
	HIWORD = CLng("&H" & Left(hexstr, 4))
End Function

Description & Usage

The HIWORD macro isolates the high-order word from a 32-bit integer.

Return Value

The macro returns the high-order word of the 32-bit integer passed to it.

Visual Basic-Specific Issues

The method I present for extracting the high-order word may seem unusual, since I first convert the value into an 8-digit hex string and then cut that in half. I do this because it is the only way that works 100% of the time in Visual Basic. All the math-based routines I've seen to do this fail when the &H80000000 bit of dwValue is set, because VB then sees it as a negative number.

Parameters

dwValue
The 32-bit integer to extract the high-order word from.

See Also

LOWORD

Back to the Macro list.
Back to the Reference section.


Last Modified: July 30, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/h/hiword.html