Hello everyone.
In my API class I encountered a lot of times I had to Get/Set low/high order <something> of <something>. For example, get the low order integer from a long. I made a few functions for this:
Before I start using these functions permanently, I come to ask if it contains any bugs, especially because of the Unsigned/Signed issue.Code:Public Shared Function LHByteCombine(ByVal low As Byte, ByVal high As Byte) As Short Return low + high * 2 ^ 8 End Function Public Shared Function LHShortCombine(ByVal low As Short, ByVal high As Short) As Integer Return low + high * 2 ^ 16 End Function Public Shared Function LHIntegerCombine(ByVal low As Integer, ByVal high As Integer) As Long Return low + high * 2 ^ 32 End Function Public Shared Function GetHighByte(ByVal value As Short) As Byte Return value >> 8 End Function Public Shared Function GetHighShort(ByVal value As Integer) As Short Return value >> 16 End Function Public Shared Function GetHighInteger(ByVal value As Long) As Integer Return value >> 32 End Function Public Shared Function GetLowByte(ByVal value As Short) As Byte Return value - GetHighByte(value) * 2 ^ 8 End Function Public Shared Function GetLowShort(ByVal value As Integer) As Short Return value - GetHighShort(value) * 2 ^ 16 End Function Public Shared Function GetLowInteger(ByVal value As Long) As Integer Return value - GetHighInteger(value) * 2 ^ 32 End Function




Reply With Quote