This should be an easy one for folks, but how do I pull off an unsigned left shift in VB.NET while using Option Strict
?
Maybe I am doing it wrong, but while trying to implement my own IP2Long function (I have my reasons), I'm testing things to make sure I have my head wrapped around the conversion process properly. I tried a few tests, and all seem to cause 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 last one is especially befuddling. 172 << 24
is a mere 2,885,681,152, well under the limit imposed by the UInt32 data type. My assumption is .NET is doing the left-shift in signed mode, then tries to convert, to unsigned, and this tosses up some kind of error.
Basically, my question boils down to this: why do unsigned numerics have to act like such hacks to the .NET framework at times? Is it really that hard for Microsoft to make unsigned data types intrinsic to the framework?