What is the difference between Int32 and UInt32?

☆樱花仙子☆ 提交于 2019-12-05 13:52:06

问题


What is the difference between Int32 and UInt32?

If they are the same with capacity range capabilities, the question is for what reason UInt32 was created? When should I use UInt32 instead of Int32?


回答1:


UInt32 does not allow for negative numbers. From MSDN:

The UInt32 value type represents unsigned integers with values ranging from 0 to 4,294,967,295.




回答2:


An integer is -2147483648 to 2147483647 and an unsigned integer is 0 to 4294967295.

This article might help you.




回答3:


uint32 is an unsigned integer with 32 bit which means that you can represent 2^32 numbers (0-4294967295).

however in order to represent negative numbers one bit of the 32 bits is reserved to indicate positive or negative number. this leaves you with 2^31 possible numbers in the negative and also in the positive. the resulting range is -2147483648 to 2147483647 (positive range includes the value 0, hence only 2147483647). this representation is called int32.

you should choose unsigned for numbers which can't get negative by definition since it offers you a wider range, but you should keep in mind that converting from and to int32 is not possible since int32 can't hold the range of uint32 and vice versa.




回答4:


UInt32 is unsigned. It can't be used to represent negative numbers but can hold greater positive numbers.



来源:https://stackoverflow.com/questions/2307271/what-is-the-difference-between-int32-and-uint32

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!