-
Does somebody have the code to split a long into two integers (the high and the low word)?
I have got the High Word so far (by integer division by &H10000).
Even better would be if I could have a hint about how to split an integer. This one is even more difficult. I need bit 0 to 9, and bit 10 to 15 in seperate (integer) variables.
If anybody could point me in the right direction would be great.
-
Hi
The way I split my 2 byte integers is.
Low byte:
LowByte = IntValue And &hFF
High Byte
HighByte = (IntValue And &hff00)/ 256
HTH
Geoff
-
-
Thanks very much, I already figured out how to split the double word into two words. It appears that I don't need to split a word into a 6 and a 10 bit value for the moment, so I will let that rest until needed.
This is how I did it:
Code:
Private Function HW(lngInput As Long) As Integer
' returns high word (Bit 16 t/m 31)
HW = lngInput \ &H10000
End Function
Public Function LW(ByVal lngInput As Long) As Integer
' returns low word (Bit 0 t/m 15)
Dim lngTemp As Long
Dim blnAddBit As Boolean
blnAddBit = False
lngTemp = lngInput And &HFFFF&
If lngTemp And &H8000& Then
' prevent overflow
lngTemp = lngTemp And &H7FFF
blnAddBit = True
End If
If blnAddBit Then lngTemp = (lngTemp Or &H8000)
LW = CInt(lngTemp)
End Function