About computer source code, inverse code and complement code The complement of a negative number is its original code. In addition to the sign bit, it "negates each bit" and adds 1 to the lowest bit. For example, the complement of - 79 is 10110001, and the complement of - 80 is 10110010?

About computer source code, inverse code and complement code The complement of a negative number is its original code. In addition to the sign bit, it "negates each bit" and adds 1 to the lowest bit. For example, the complement of - 79 is 10110001, and the complement of - 80 is 10110010?


-The complement of 80 is 101110000. First calculate the binary of 80 as 1010000, then take the inverse code 0101111, add 1 to get the complement 011000, and then add the sign bit (negative sign is 1), so the complement of - 80 is 101110000



Original code, inverse code, complement code, negative number representation in computer?


1: For positive numbers, the original code and inverse code, complement are the same, are positive numbers themselves
For negative numbers, the original code is binary with sign bit 1 and absolute value of X taken as the numerical part
The inverse code is the sign bit 1, and the other bits are the inverse of the original code
The complement is the sign bit 1, the other bits are the inverse of the original code, and the non bit plus 1
That is to say, the complement of a negative number is its inverse plus 1
Code shift is the complement that reverses the sign bit
2: In a computer, there is actually only addition, and subtraction has to be converted into addition,
Multiplication is converted to addition and division to subtraction
3: In the computer, any binary with sign is operated and stored in the form of its complement. The reason why it is processed in the form of complement rather than in the form of original code and inverse code is that the computer has problems in processing the original code and inverse code with sign bit
According to the complement method, on the one hand, the symbol bits and the effective value part can participate in the operation together, so as to simplify the operation rules. On the other hand, the subtraction operation is converted into the addition operation, so as to further simplify the circuit design of the calculator in the computer
4: Formula of complement addition and subtraction
1) Complement addition formula
[x + y] complement = [x] complement + [y] complement
2) Complement subtraction formula
[X-Y] complement = [x] complement - [y] complement = [x] complement + [- y] complement
It is known that the rule of finding [- y] complement from [+ y] complement is to add 1 after the whole part (including sign bit) is reversed
5: Find the original code from the complement
Given the complement of a number, there are two operations to find the original code
1. If the sign bit of the complement is "0", it means a positive number, so the complement is the original code of the number
2. If the sign bit of the complement is "1", it means that it is a negative number. The operation of finding the original code can be: the sign bit is 1; the other bits are negated, and then the whole number is added with 1
Taking 8-bit binary operation as an example, the operation value range is - 128 ~ 127
So to sum up, we can get - 126-100, which can be seen as (- 126) + (- 100), in order to make the subtraction operation into addition
-126 - & gt; 1111 1110 - & gt; reverse 1000 0001 - & gt; supplement 1000 0010
100 - & gt; 0110 0100 - & gt; complement 1001 1011 + 1 - & gt; complement 1001 1100
Add the complements to get - 126 complements + (- 100) complements - & gt; 1000, 010 complements + 1001, 1100 complements - & gt; 1, 0001, 1110 complements - & gt; naturally discard more than 0001, 1110 complements
Get 0001 1110 complement - & gt; 0001 1110 original from complement
The result is 00011110. If two negative numbers are added and overflow occurs, then the result must be positive



Find out the complement of 45 and - 45 in 8-bit machine


The complement of the original code
45 00101101 00101101 00101101
-45 10101101 11010010 11010011



The complement of the original code
Suppose that the number of machines in a computer is 8 bits, try to write the original code, inverse code and complement of decimal number - 57


Original code: 10111001
Inverse code: 11000110
Complement: 11000111



What is the complement and inverse of the original code?
Don't tell me that the positive number XXX is itself or something
I just want to know the definition of the complement and inverse of the original code


1、 Original code
The original code representation is a simple representation of machine number. Its sign bit is 0 for positive sign, and: for negative sign. The value is generally expressed in binary form
Find the original code: X ≥ 0, then the symbol bit is 0, the rest copy;
If x ≤ 0, the sign bit is 1 and the rest are copied
[example 1] x = + 1001001 [x] original = 01001001
[example 2] x = - 1001 [x] original = 11001001
2、 Inverse code
The inverse code of a machine number can be obtained from the original code. If the machine number is a positive number, the inverse code of the machine number is the same as the original code; if the machine number is a negative number, the inverse code of the machine number is obtained by taking its original code (except the sign bit) instead. If there is a number x, the inverse code of X is denoted as [x] inverse
Inverse code: if x ≥ 0, the sign bit is 0, the rest copy;
If x ≤ 0, the sign bit is 1, and the others are reversed
[example 3] x = + 1001 [x] inverse = 01001001
[example 4] x = - 1001001 [x] inverse = 10110110
3、 Complement
The complement of the machine number can be obtained from the original code. If the machine number is positive, then the complement of the machine number is the same as the original code; if the machine number is negative, then the complement of the machine number is obtained by negating each bit of its original code (except the sign bit) and adding 1 to the non bit
Complement: if x ≥ 0, the sign bit is 0, and the rest are copied;
If x ≤ 0, the sign bit is 1, and after the others are negated, the lowest bit is added with 1
[example 5] x = + 1001 [x] complement = 01001001
[example 6] x = - 1001001 [x] complement = 10110111



What are the source code, complement code and inverse code of 0


When defining the original code, inverse code and complement code of 0, it should be noted that the computer needs to distinguish the 0 here into positive 0 and negative 0, so
(8 digits) original code: 00000000 inverse code: 00000000 complement code: 00000000
10000000 11111111



Calculate the original code, inverse code and complement code
zero point one zero one one
-10110
Calculate the source code, inverse code and complement of the two


The three yards of positive numbers are the same
The first place of the original code of a negative number is 1, followed by the binary code of the corresponding positive number
On the basis of the original code, the inverse code has the same sign bit, and the rest is negated
No code, add 1 to the inverse code
The complement of the original code
So the original code is 0.1011
Original code 0.1011
Original code 0.1011
Original code: 110110
Original code: 101001
Original code: 101010



What is the calculation relationship between the original code, the inverse code and the complement code?


Original code
The sign bit of a positive number is 0, the sign bit of a negative number is 1, and the other bits represent the absolute value of a number according to the general method. The original code of a number is obtained by this method
Inverse code
For a signed number, the inverse code of a positive number is the same as the original code, and the inverse code of a negative number is the bit by bit negation of the original code except the sign bit
Complement
The complement of a positive number is the same as its original code, and the complement of a negative number is its inverse code plus one at the lowest position



The calculation of the inverse of the original complement code
Write out the 8-bit binary representation of decimal numbers - 15, + 28, - 37, - 55


x = -15d = -1111b
[x] Original = 1000 1111b
[x] Inverse = 1111 0000b
[x] Complement = 1111 0001b
.
x = +28d = +1 1100b
[x] Original = 0001 1100B
[x] Inverse = 0001 1100B
[x] Complement = 0001 1100B
.
x = -37d = -10 0101b
[x] Original = 1010 0101b
[x] Inverse = 1101 1010b
[x] Complement = 1101 1011b
.
x = -55d = -11 0111b
[x] Original = 1011 0111b
[x] Inverse = 1100 1000B
[x] Complement = 1100 1001b



The 8-bit complement operands 10101010 are shifted left and right by one bit respectively, and the 8-bit complement operands 10101010 are logically shifted left and right by one bit respectively
For the 8-bit complement operands 10101010, it is necessary to shift the number one bit to the left and one bit to the right
The 8-bit operands 10101010 are logically shifted one bit left and right respectively


Arithmetic shift right: 11010101
Arithmetic shift left: 01010100
Logical shift left: 01010100
Logical shift right: 01010101