Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Integer overflow problem, explained in detail.
Integer overflow problem, explained in detail.
Well, an integer of type int is represented by four bytes (the number of bytes on a general machine is different from one machine to another), that is, 4*8=32-bit binary, 2 32 = 4 294 967 296, that is to say, it can represent at most 4 294 967 296 integers, that is to say, it has 4 294. To sum up, if an integer is represented by an n-bit binary, then there are (2 (n- 1))- 1 positive numbers, 2 (n- 1) negative numbers and a 0.

Your machine seems to use 16 bits (2 bytes) to represent integers (int type). So the largest positive number is 32767, and the corresponding binary number is 011111165438+. If you add 1, it becomes 100000000000, which is the complement form of -32768.