How does a negative number in C indicate it?

Source: Internet
Author: User
Why is the range of signed integer values in C from-32768 ~ 32767
Reward score: 5-resolution time:
Try to explain it in detail! For example, if the 16 1111111111111111 first bits are signed bits, this should be-32767, then how does-32768 use 16-bit binary to represent it?
Question added: How does one calculate the Binary Expression of a negative number?
For example:
-1 binary
-Binary 32767

Answer:
-2 ^ 15 ~ (2 ^ 15-1)
The number in the computer is stored as a complement
The main reason is that the complement code can be used to process the symbol bit and other digits in a unified manner. At the same time, the subtraction can also be processed by addition. The other two are supplemented.
If the highest bit (symbol bit) has a forward bit, the carry is discarded.

In C, high position 1 is used to represent a negative number. The Int type occupies 16 bytes in total. The 32768 binary value is, and the high value is 1. The system will regard it as a negative number, therefore, 32768 is represented in a long format, which occupies four bytes. The highest bit is not 1. (00000000,00000000, 0000000,00000000)
-In the memory, 32768 indicates and. The process is: first read the positive value 32768 (,), then take the reverse value (0111111111111), and then add 1)

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.