Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Why do integer variables range from -32768 to 32767 instead of -32767 to 32767? So what is the storage form of -32768 in memory?
Why do integer variables range from -32768 to 32767 instead of -32767 to 32767? So what is the storage form of -32768 in memory?
The computer uses "complement method" to represent negative numbers in binary. The method is that the positive number is based on the original code, and the negative number is added by the inverse code of its inverse number. This result replaces "-0" with -32768, which can make the sign bit and the effective value part participate in the operation together, thus simplifying the operation rules; At the same time, the subtraction operation is converted into addition operation, which further simplifies the circuit design of the operator in the computer.

Use the complement 1000 0000 as the storage form of decimal number -32768 in memory. 1000 0000 is a complement form, and the process of calculating its true value is to add 1, that is,11111.

Extended data:

If you specify a number that is out of the integer range, it will be interpreted as floating point. Similarly, if the result of the operation is out of the range of integers, it will also return a floating-point type.

To explicitly convert a value to an integer variable, you can use (int) or (integer)? Forced conversion. However, in most cases, there is no need to cast, because when an operator, function or process control requires an integer parameter, the value is automatically converted. When converting from floating-point type to integer type, numbers will be rounded (decimal places will be discarded).