1. Definition of source code, reverse code, and complement code
1. Original code
Use the highest bit as the sign bit (0 represents positive, 1 represents negative), and the rest represent the absolute value of the value (in binary format ).
For simplicity, we use 1 byte to represent an integer.
+ The original Code of 7 is: 00000111
-The original Code of 7 is: 10000111
2. Anti-code
If a number is positive, its anticode is the same as the original code. If a number is negative, the symbol bit is 1, and the rest of the codes are reversed.
For simplicity, we use 1 byte to represent an integer:
+ The Anti-Code of 7 is 00000111.
-The Anti-Code of 7 is 11111000.
3. Complement
Complement: If a number is positive, the original code, the reverse code, and the complement code are the same; if the number is negative, the signed bit is 1, and the rest are reversed, then the entire number plus 1. For simplicity, we use 1 byte to represent an integer:
+ 7 completion code: 00000111
-7: 11111001
To convert a negative complement to a decimal number, follow these steps:
1. Get the opposite information for you first;
2. convert it to a decimal number;
3. Add a negative number and subtract 1.
For example:
11111010, the highest bit is 1, is a negative number, first take the inverse 00000101 for everyone, convert to the decimal number 5, add the negative number-5, then minus 1-6.
2. FAQs
Why is int A = 232 negative when I convert int A = to byte type ???