to int
what's correct method to convert a long to an integer?. How to convert signed integer to unsigned integer?.
[112 byte] By [
ikcha] at [2007-11-20 11:37:11]

# 1 Re: to int
Keep in mind 2 important things:
1. Long = 4 bytes, Integer = 2 bytes
2. In VB, there is no such thing as an Unsigned Integer, only signed
Long To Integer (Signed, not Unsigned):
Public Function LongToInt(LongValue As Long) As Integer
If LongValue And &H8000& Then
LongToInt= LongValue Or &HFFFF0000
Else
LongToInt= LongValue And &HFFFF&
End If
End Function
Signed Integer to unsigned integer. Again, no such thing as unsigned int, but you can use Long:
Public Function SignedIntToUnsigned(IntegerValue As Integer) As Long
SignedIntToUnsigned = (IntegerValue And &HFFFF&)
End Function