Article directory
1. Original code
The original code is the binary representation of the decimal number. For example, a number of type int occupies 4 bytes, and a byte is 8 bits, so a number of type int occupies 32 bits.
Example: the original code of 10
00000000 00000000 00000000 00001010
The highest bit of the negative original code represents the sign bit, and 1 represents a negative number
Example: the original code of -10
10000000 00000000 00000000 00001010
Two, inverse code
The negative code of a positive number is the same as the original code.
For example, the 10 inverse code above is:
00000000 00000000 00000000 00001010
The one's complement of a negative number is that the highest sign bit remains unchanged, and the rest are reversed.
For example, the inverse code of -10 above is:
11111111 11111111 11111111 11110101
Three, complement
The complement code of a positive number is the same as the original code and the inverse code, and remains unchanged.
For example, the 10 inverse code above is:
00000000 00000000 00000000 00001010
The complement of a negative number is its complement plus 1 to become the complement.
For example, the complement of -10 above is:
11111111 11111111 11111111 11110110
Four. Summary
For positive numbers, the three codes of original code, inverse code and complementary code are the same.
For negative numbers, the highest bit represents the sign bit, and the inverse code means that the sign bit remains unchanged, and the remaining bits are inverted. Complement is one's complement plus 1.
When the computer stores, the number is stored in the form of two's complement.