1. Definition of original code, counter code and complement
1. Original code
The highest bit is the symbol bit (0 is the positive, 1 represents the negative), and the remainder represents the absolute value of the value itself (in binary notation).
For the sake of simplicity, we use 1 bytes to represent an integer.
+7 The original code: 00000111
-7 of the original code: 10000111
2. Anti-code
If a number is positive, then its inverse code is the same as the original code; If a number is negative, the sign bit is 1, and the rest of you are against the original code.
For the sake of simplicity, we use 1 bytes to represent an integer:
+7 of the Counter code is: 00000111
-7 of the code is: 11111000
3. Complement
Complement: If a number is positive, then its original code, inverse code, complement the same; If a number is negative, then the sign bit is 1, and the rest of you are against the original code, and then the whole number plus 1. For the sake of simplicity, we use 1 bytes to represent an integer:
+7 's complement is: 00000111
-7 's complement is: 11111001
The complement of a negative number is known, converted to decimal, and steps:
1, first to you take counter;
2, convert it to decimal number;
3, plus minus, minus 1.
For example:
11111010, the highest bit is 1, is negative, first to you get the reverse 00000101, converted to decimal number 5, plus minus 5, minus 1 to 6.
2. Frequently Asked Questions
Why is the negative number when I a=232 int to the byte type???