Unos snippets para imitar las macros "LoByte", "LoWord", "LoDword", etc, usando la Class
BitConverter, la cual, aunque necesita hacer más trabajo, me parece una solución mucho mas elegante que las que se pueden encontrar por ahí, e igual de efectiva.
' Get LoByte
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetLoByte(1587S)) ' Result: 51
'
''' <summary>
''' Gets the low-order byte of an 'Int16' value.
''' </summary>
''' <param name="Value">Indicates the 'Int16' value that contains both the LoByte and the HiByte.</param>
''' <returns>The return value is the low-order byte.</returns>
Public Shared Function GetLoByte(ByVal value As Short) As Byte
Return BitConverter.GetBytes(value).First
End Function
' Get HiByte
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetHiByte(1587S)) ' Result: 6
'
''' <summary>
''' Gets the high-order byte of an 'Int16' value.
''' </summary>
''' <param name="Value">Indicates the 'Int16' value that contains both the LoByte and the HiByte.</param>
''' <returns>The return value is the high-order byte.</returns>
Public Shared Function GetHiByte(ByVal value As Short) As Byte
Return BitConverter.GetBytes(value).Last
End Function
' Get LoWord
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetLoWord(13959358I)) ' Result: 190S
'
''' <summary>
''' Gets the low-order word of an 'Int32' value.
''' </summary>
''' <param name="Value">Indicates the 'Int32' value that contains both the LoWord and the HiWord.</param>
''' <returns>The return value is the low-order word.</returns>
Public Shared Function GetLoWord(ByVal value As Integer) As Short
Return BitConverter.ToInt16(BitConverter.GetBytes(value), 0)
End Function
' Get HiWord
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetHiWord(13959358I)) ' Result: 213S
'
''' <summary>
''' Gets the high-order word of an 'Int32' value.
''' </summary>
''' <param name="Value">Indicates the 'Int32' value that contains both the LoWord and the HiWord.</param>
''' <returns>The return value is the high-order word.</returns>
Public Shared Function GetHiWord(ByVal value As Integer) As Short
Return BitConverter.ToInt16(BitConverter.GetBytes(value), 2)
End Function
' Get LoDword (As Unsigned Integer)
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetLoDword(328576329396160UL)) ' Result: 2741317568UI
'
''' <summary>
''' Gets the low-order double word of an 'UInt64' value.
''' </summary>
''' <param name="Value">Indicates the 'UInt64' value that contains both the LoDword and the HiDword.</param>
''' <returns>The return value is the low-order double word.</returns>
Public Shared Function GetLoDword(ByVal value As ULong) As UInteger
Return BitConverter.ToUInt32(BitConverter.GetBytes(value), 0)
End Function
' Get HiDword (As Unsigned Integer)
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetHiDword(328576329396160UL)) ' Result: 76502UI
'
''' <summary>
''' Gets the high-order double word of an 'UInt64' value.
''' </summary>
''' <param name="Value">Indicates the 'UInt64' value that contains both the LoDword and the HiDword.</param>
''' <returns>The return value is the high-order double word.</returns>
Public Shared Function GetHiDword(ByVal value As ULong) As UInteger
Return BitConverter.ToUInt32(BitConverter.GetBytes(value), 4)
End Function
' Get LoDword (As Signed Integer)
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetLoDword(328576329396160L)) ' Result: -1553649728I
'
''' <summary>
''' Gets the low-order double word of an 'Int64' value.
''' </summary>
''' <param name="Value">Indicates the 'Int64' value that contains both the LoDword and the HiDword.</param>
''' <returns>The return value is the low-order double word.</returns>
Public Shared Function GetLoDword(ByVal value As Long) As Integer
Return BitConverter.ToInt32(BitConverter.GetBytes(value), 0)
End Function
' Get HiDword (As Signed Integer)
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetHiDword(328576329396160L)) ' Result: 76502I
'
''' <summary>
''' Gets the high-order double word of an 'Int64' value.
''' </summary>
''' <param name="Value">Indicates the 'Int64' value that contains both the LoDword and the HiDword.</param>
''' <returns>The return value is the high-order double word.</returns>
Public Shared Function GetHiDword(ByVal value As Long) As Integer
Return BitConverter.ToInt32(BitConverter.GetBytes(value), 4)
End Function
' Make Word
' ( By Elektro )
'
' Usage Examples:
' MsgBox(MakeWord(51S, 6S)) ' Result: 1587S
'
''' <summary>
''' Makes an 'Int16' value from two bytes.
''' </summary>
''' <param name="LoByte">Indicates the low-order byte.</param>
''' <param name="HiByte">Indicates the high-order byte.</param>
''' <returns>The 'Int16' value.</returns>
Public Shared Function MakeWord(ByVal LoByte As Byte,
ByVal HiByte As Byte) As Short
Return BitConverter.ToInt16(New Byte() {LoByte, HiByte}, 0)
End Function
' Make Dword
' ( By Elektro )
'
' Usage Examples:
' MsgBox(MakedWord(190S, 213S)) ' Result: 13959358I
'
''' <summary>
''' Makes an 'Int32' value from two 'Int16' values.
''' </summary>
''' <param name="LoWord">Indicates the low-order word.</param>
''' <param name="HiWord">Indicates the high-order word.</param>
''' <returns>The 'Int32' value.</returns>
Public Shared Function MakeDword(ByVal LoWord As Short,
ByVal HiWord As Short) As Integer
Dim LoBytes As Byte() = BitConverter.GetBytes(LoWord)
Dim HiBytes As Byte() = BitConverter.GetBytes(HiWord)
Dim Combined As Byte() = LoBytes.Concat(HiBytes).ToArray
Return BitConverter.ToInt32(Combined, 0)
End Function
' Make Long (From An Unsigned Integer)
' ( By Elektro )
'
' Usage Examples:
' MsgBox(MakeLong(2741317568UI, 76502UI)) ' Result: 328576329396160UL
'
''' <summary>
''' Makes an 'UInt64' value from two 'UInt32' values.
''' </summary>
''' <param name="LoDword">Indicates the low-order Dword.</param>
''' <param name="HiDword">Indicates the high-order Dword.</param>
''' <returns>The 'UInt64' value.</returns>
Public Shared Function MakeLong(ByVal LoDword As UInteger,
ByVal HiDword As UInteger) As ULong
Dim LoBytes As Byte() = BitConverter.GetBytes(LoDword)
Dim HiBytes As Byte() = BitConverter.GetBytes(HiDword)
Dim Combined As Byte() = LoBytes.Concat(HiBytes).ToArray
Return BitConverter.ToUInt64(Combined, 0)
End Function
' Make Long (From a Signed Integer)
' ( By Elektro )
'
' Usage Examples:
' MsgBox(MakeLong(-1553649728I, 76502I)) ' Result: 328576329396160L
'
''' <summary>
''' Makes an 'Int64' value from two 'Int32' values.
''' </summary>
''' <param name="LoDword">Indicates the low-order Dword.</param>
''' <param name="HiDword">Indicates the high-order Dword.</param>
''' <returns>The 'Int64' value.</returns>
Public Shared Function MakeLong(ByVal LoDword As Integer,
ByVal HiDword As Integer) As Long
Dim LoBytes As Byte() = BitConverter.GetBytes(LoDword)
Dim HiBytes As Byte() = BitConverter.GetBytes(HiDword)
Dim Combined As Byte() = LoBytes.Concat(HiBytes).ToArray
Return BitConverter.ToInt64(Combined, 0)
End Function