VB icon

HiByte,HiWord,LoByte,LoWord, MakeInt and MakeLong

Email
Submitted on: 1/16/2015 7:00:00 PM
By: Duncan Jones (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 2201
 
     Often especially when dealing with the API, byte and integer data types will be packed into LONG INTEGER (32 bit) values. Thes snippets allow you to decode/encode these 32 bit longs:
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: HiByte,HiWord,LoByte,LoWord, MakeInt and MakeLong
' Description:Often especially when dealing with the API, byte and integer data types will be packed into LONG INTEGER (32 bit) values.
Thes snippets allow you to decode/encode these 32 bit longs:
' By: Duncan Jones (from psc cd)
'**************************************

Public Function hiByte(ByVal w As Integer) As Byte
If w And &H8000 Then
 hiByte = &H80 Or ((w And &H7FFF) \ &HFF)
Else
 hiByte = w \ 256
End If
End Function
Public Function HiWord(dw As Long) As Integer
 If dw And &H80000000 Then
 HiWord = (dw \ 65535) - 1
 Else
HiWord = dw \ 65535
 End If
End Function
Public Function LoByte(w As Integer) As Byte
 LoByte = w And &HFF
End Function
Public Function LoWord(dw As Long) As Integer
 If dw And &H8000& Then
 LoWord = &H8000 Or (dw And &H7FFF&)
Else
 LoWord = dw And &HFFFF&
End If
End Function
Public Function MakeInt(ByVal LoByte As Byte, ByVal hiByte As Byte) As Integer
MakeInt = ((hiByte * &H100) + LoByte)
End Function
Public Function MakeLong(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
MakeLong = ((HiWord * &H10000) + LoWord)
End Function


Other 17 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.