The range represented by int in Visual C + +

Source: Internet
Author: User

int integral type in Visual C + + is typically represented by four bytes

to store an int in a computer in the form of a complement (for a positive number whose complement is equal to the original code),

Complement of numbers from 0000 0000 0000 0000 0000 0000 0000 0000~1111 1111 1111 1111 1111 1111 1111 1111

The conversion rules of the complement and the original code, 1111 1111 1111 1111 1111 1111 1111 1111 indicates a value of-1;

1111 1111 1111 1111 1111 1111 1111 1110 indicates a value of-2;

1111 1111 1111 1111 1111 1111 1111 1101 Indicates a value of-3;

1000 0000 0000 0000 0000 0000 0000 0001 Indicates a value of-2147483647;

the 1000 0000 0000 0000 0000 0000 0000 0000 is rigidly defined as-2147483648;

Simplification of the understanding:

For a 8-byte integer (int), the range is 2 of the 8-square, representing -128~127. As shown in the table below, if you use the original code and the inverse code,

+0 and 0 are the same number but there are two different representations, which will not only make the computer more layer processing, but also waste a representation range, and the complement can be a good solution to the problem.

(-128 has only the complement, not the original code and the inverse code, because the value bit can only represent 0~127. )

The range represented by int in Visual C + +

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.