Changes in the value of int and uint during conversion

Source: Internet
Author: User
Int type data is converted to uint type: Because Int Is a signed type, when int is a positive number, int type data is converted to uint without changing. When int is a negative number and INT type data is converted to uint type, the value changes. However, the conversion process does not remove the previous negative number, for example, int A =-1; uint B = (uint) A; then the result of B is not 1; but 4294967295; we know that data stored in the computer is stored by the complement code. The Int size is 4 bytes, that is, 32 bits, and the first bits are the symbol bits; the size of the uint is also 4 bytes, 32 bits, but no symbol bit. If int A =-1, the complement code is stored in the computer: 1111 1111 1111 1111; the first digit is the symbol bit. Run uint B = (uint) A. when the data is converted to the uint type, the bucket still stores the complement code: 1111 1111 1111 1111; no sign bit. Then the value is 4294967295. Program : Static void main (string [] ARGs) {// calculate the maximum and minimum int A = 1, sum = 0; For (INT I = 0; I <= 30; I ++) {sum + = A; A * = 2;} console. writeline ("the maximum value of int type is:" + sum); // 0111 1111 1111 1111 2147483647 the result is sum ++; console. writeline ("the minimum value of the int type is:" + sum); // 1000 0000 0000 0000 2147483648 result is-} This article is from the csdn blog. For more information, see file: /// G:/Peng huabin/learning/change of the value between int and uint % 20-% 20 live % 20-% 20csdn blog. MHT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.