My doubts
An 8-bit bytes, where the most significant bit represents positive and negative numbers, 0 for positive, 1 for negative. It can be represented by -128 ~ + 127.
+127 01111111 can be represented. This is no problem for some positive numbers, negative numbers this section there are two questions
11111111 -127 can only express ah, there are 10 million represents what ah, is -0. This does not make sense ah, in fact, is represented by -128, but will appear in the calculation problems, such as mathematics, 1 + (- 1) = 0, but in binary 00000001 + 10000001 = 10000010, converted to decimal - 2.
Solve the problem
In fact, there will be a positive number in the computer are saved as complement. For positive numbers is the complement itself, negative for its anti-complement code is +1 ( anti-code: The bitwise binary number ). We give an example
127-128, typically in a computer are used in addition.
127 | -128 | |
Original code | 01111111 | 10000000 |
Inverted | 11111111 | |
Complement | 01111111 | 10000000 |
127 01111111
-128 10000000
11111111 Because this is a complement, anti-code is converted to 11111110, the original code is 10000001 = -1
Why the 8-bit binary value range is -128 to 127, it refers to the complement of the range.
An interesting discovery
Inside the mold - the negative absolute value of the original code = complement (see first reference address can)
My definition of mold. Each bit can save the number 2, that is, its capacity. For an 8-bit binary byte, it is the die = 256, which is -128 to + 127 inside integer number.
reference
The first comparison classic
https://blog.csdn.net/leonliu06/article/details/78685197
https://zhidao.baidu.com/question/143216665.html