1
If you cast to int rather than uint, then this will give you the exact negative number but test4 will need to be an int (or long) rather than a uint variable, otherwise you'll get a conversion error.
As a general rule, it's best to avoid the unsigned integral types unless you really need the additional range or you're inter-operating with unmanaged code which uses unsigned types.
Accepted 0
hi,
As per my knowledge maximum value is supported by uint is 4294967295, when you trying to assign nagative value or cast nagative value then it perform substraction.
Example:
int j = 0;
uint kkk = (uint)(j - 23232);
interanlly it perform 4294967295 + 0 - 23232 + 1 = 4294944064
this only true for nagative value
hope this will help you.
0
Yes, I'd declare test4 to be either int or, if the result could exceed + or - 2 billion, long.
0
Agreed. I was on the slow bus. Can I assigned to a signed type or just declare as a long?
0
The unsigned versions with the same bit sizes. Effectively, this means they cannot store negative numbers, but on the other hand they can store positive numbers twice as large as their unsigned counterparts.
The limits for int (32 bit) are:
int: –2147483648 to 2147483647
uint: 0 to 4294967295 And for long (64 bit):
long: -9223372036854775808 to 9223372036854775807
ulong: 0 to 18446744073709551615