Extracting the lower and upper byte of an integer
Sometimes, especially when dealing with the API, it can be useful to extract the lower and upper byte of an integer. VB doesn't support retreiving individual bytes of an integer in an easy manner, so we have to do bit masking and shifting to get it right:
Author: Sub HiLoByte (ByVal Intg As Integer, LoByte As Integer, HiByte As Integer) LoByte = Intg And &HFF& HiByte = (Intg And &HFF00&) / 256 End SubThose using Visual Basic 4.0 or higher can replace LoByte As Integer, HiByte As Integerwith LoByte As Byte, HiByte As Bytefor more coherent operation. |
||
Editor: Last update: 2024-12-26 Copyright 1995-2024 VBI |