How the computer does the arithmetic
in a computer system, the values are all represented by the complement.
Positive complement and source code are the same.
The sign bit is unchanged, and the other bits are reversed plus 1.
An expression |
Convert to Anti-code |
Shift to complement |
Calculation results |
Switch to source code |
10+2 |
0000 1010 + 0000 0010 |
0000 1010 + 0000 0010 |
0000 1100 |
0000 1100 |
+ ( -2) |
0000 1010 + 1111 1101 |
0000 1010 + 1111 1110 |
0000 1000 |
0000 1000 |
All ( -4) |
0000 0011 + 1111 1011 |
0000 0011 + 1111 1100 |
1111 1111 |
1000 0001 |
Note: Positive inverse code is the same as the source code is the same, negative inverse code is negative absolute value of the bitwise negation, complement is negative absolute value reversed, sign bit unchanged plus a
This article from "Technology bo" blog, declined reprint!
Python series------Computer operation process