VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



HiByte,HiWord,LoByte,LoWord, MakeInt and MakeLong

by Duncan Jones (19 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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:

Rate HiByte,HiWord,LoByte,LoWord, MakeInt and MakeLong

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

Download this snippet    Add to My Saved Code

HiByte,HiWord,LoByte,LoWord, MakeInt and MakeLong Comments

No comments have been posted about HiByte,HiWord,LoByte,LoWord, MakeInt and MakeLong. Why not be the first to post a comment about HiByte,HiWord,LoByte,LoWord, MakeInt and MakeLong.

Post your comment

Subject:
Message:
0/1000 characters