Suppose I have 4 separate bytes that i need to arrange in a
single variable of Long data type (IP address, to be specific)
I don't care about sign, just need to put bit data into a variable of
4 bytes size.
This seemed like a trivial thing to me, but the function below
generates Overflow.
Furthermore, I tried to use Currency data type, and surprisingly,
still getting Overflow error.
Is there any way to just shift bits in a Long? I can do it easily in
C/C++, but don't know about VB
single variable of Long data type (IP address, to be specific)
I don't care about sign, just need to put bit data into a variable of
4 bytes size.
This seemed like a trivial thing to me, but the function below
generates Overflow.
Code:
Private Function toLong(ByVal n1 As Long, ByVal n2 As Long,
ByVal n3 As Long, ByVal n4 As Long) As Long
toLong = (n1 * (CLng(&H100) ^ 3)) Or (n2 * (CLng(&H100) ^ 2))
Or (n3 * CLng(&H100)) Or CLng(n4)
End Function
Furthermore, I tried to use Currency data type, and surprisingly,
still getting Overflow error.
Code:
Private Function toLong(ByVal n1 As Currency, ByVal n2 As
Currency, ByVal n3 As Currency, ByVal n4 As Currency) As Currency
toLong = (n1 * (CCur(&H100) ^ 3)) Or (n2 * (CCur(&H100) ^ 2))
Or (n3 * CCur(&H100)) Or CCur(n4)
End Function
Is there any way to just shift bits in a Long? I can do it easily in
C/C++, but don't know about VB