Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - In c language, does int cross-border become positive or negative, the minimum cross-border becomes positive, and the maximum cross-border becomes negative? Why?
In c language, does int cross-border become positive or negative, the minimum cross-border becomes positive, and the maximum cross-border becomes negative? Why?
Take 16 bit int as an example.

First of all, you should understand that the numbers stored in memory are complements.

The smallest number is -32768, and its complement is1000,000,000,000,000,000,000,000,000,000. The complement of-1 is11,1 1 1, 165438.

-32768- 1=[-32768]+[- 1]= 1000,0000,0000,0000+ 1 1 1 1, 1 1 1 1, 1 1 1 1, 1 1 1 1=0 1 1 1, 1 1 1 1, 1 1 1 1, 1 1 1 1

=32767

The maximum value is 32767, and its complement is 0 1 1,11,11,65538. The complement of 1 is 0000,0000,0001.

32767+ 1=0 1 1 1, 1 1 1 1, 1 1 1 1, 1 1 1 1+0000,0000,0000,000 1= 1000,0000,0000,0000

=-32768