This should be easy for people, but how can I remove the unsigned left shift in VB.NET when usingOption Strict
Maybe I'm doing it wrong, but trying to implement my own IP2Long function (I have my own reasons), I am testing things to make sure that I have a head wrapped around the conversion process properly. I tried several tests and everything seems to be causing errors.
Dim a As Int32
a = CUint(172 << 24) 'Constant expression not representable in type 'UInteger'
a = DirectCast((172 << 24), UInt32) 'Value of type 'Integer' cannot be converted to 'UInteger'
a = Convert.ToUInt32(172 << 24) 'Compiles, but throws an OverflowException
The latter is especially clogging. 172 << 24- this is only 2 855 681 152 people, which corresponds to the limit imposed by the UInt32 data type. My guess: .NET performs a left shift in signed mode, then tries to convert to unsigned, and this causes some error.
Basically, my question boils down to the following: why should unsigned numbers occasionally affect such hacks on the .NET platform? Is it really hard for Microsoft to create unsigned data types that are an integral part of the framework?
source
share