Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Why is the integer data overflow 32767+ 1 =-367678 in C language? If 32, please give a detailed process.
Why is the integer data overflow 32767+ 1 =-367678 in C language? If 32, please give a detailed process.
I said maybe you don't agree: the computer doesn't know what is negative and what is positive. It just adds a series of fixed-length 0 1 sequences according to binary rules. On the 16 bit binary platform, a * * has two 16 permutations to replace negative numbers, zero numbers and positive numbers, so that the binary is +65438. When 32767+ 1, the number of digits in the computer is 1, followed by 15 zeros, which is actually 32768 of the decimal number. But according to the above rules, this string of binary sequences should correspond to -32768, so when outputting, "the software added a'-'sign in front." If you tell the software to output unsigned numbers, then -32768 will immediately become +32768. According to the above explanation, the signed output of 32767+2 is -32767 and the unsigned output is 32769. The following code can verify:

I think you understand. ...