Calculation of binary complement
The first 1 of -1010 is not a flag bit
So to take the original code, you should put a 1 in front of it as a flag bit
And then take the inverse of each digit except for the flag bit, that is, it’s the inverse code
And then the inverse code is added 1
The final code is 10110, which is the inverse code. p>The final complement is 10110.
Detailed overview of the original inverse complement
The original code sign bit is where positive is 0 and negative is 1
The inverse of a positive number is equal to the original,
Negative numbers: the sign bit is unchanged, the rest of the bits are inverted,
Data in the form of complement in the computer, the same in the form of complement is involved in the operation
Positive numbers: original = inverse = complement
Negative numbers: the inverse of the code that is obtained in the first place, the inverse code, plus one, is added in the lowest bit.
-34=10100010 Complement: 11011110
-29=10011101 Complement: 11100011
-47=10101111 Complement: 11011111
Why you need the inverse and complement?
Inverse code: calculator operators have only adders, not subtractors,
But inverse code has a flaw, positive and negative sums of 0 are not unique
Complement: to solve the case where inverse code positive and negative sums are not unique, a high overflow is used to solve it;
11000011 Because his result is negative, you have to take his complement to get the correct result: 10111101
Positive numbers don’t need to be transferred, negative numbers need to have the complement of the negative number treated as the original code to find the complement, (the complement of the complement)
111111111110000000 [-128 complement] to find the original code
10010011 (original) 11101101 (complement)
What’s the deal with computer primitive, inverse, and complementary codes? Can you give me an example?
What is the original, inverse, and complement of a computer?
Can you give an example?
In computers, there is no original or inverse code.
What’s the deal with complementary codes?
It starts with the “complement”.
The number of bits counted by a computer is fixed, as in an eight-bit machine.
After the number of digits is limited, you can use “complements” to replace negative numbers, and use addition to realize subtraction operations.
For example, two decimal digits, -1, can be replaced by +99.
25-1 = 24
25+99 = (one hundred) 24
The two algorithms function the same way by discarding the rounding, and taking only two digits.
99, is the complement of -1. Formula: complement = one hundred + negative.
One hundred, is the counting period of two decimal numbers.
——— ———- ——
Computers use binary, complementary numbers, it is renamed: complement.
Octet binary: 00000000~11111111 (decimal 255).
The counting period is: 2^8=256.
So the -1’s complement is 256+(-1)=255=11111111 (binary).
This is the same result when you use the non-existent “inverse of the original code plus one”.
The formula for finding the complement of a negative number: period + that negative number.
Positive numbers, without conversion. It can also be said that the positive number itself is the complement.
——— ———- ——
Can you give an example?
For example, 7-3 = 4.
The calculation with the complement is as follows:
7’s complement = 00000111
– 3’s complement = 11111101
– -Sum ——– —–
Gets (1) 00000100 = 4’s complement
Discard the rounding and keep only eight bits as the result, which realizes 7 – 3.
What are the original, inverse, and complement of -x=-10?
The original, inverse, and complement of -10 are:
10001010 (original), 11110101 (inverse), and 11110110 (complement).
The machine word length is 8 bits, then the -10 original inverse complement is
If the word length is 8 bits, then:
How to represent -10’s prime, inverse and complement?
The original code of -10 is 10001010, the inverse code is 11110101, and the complement code is 11110110.
The sign bit of a negative number is 1, which means that the highest bit is 1, so when we say that the original code is the inverse code and the complement code, we have to limit the number of digits to be expressed. In simple terms, take eight bits for example:
The original code is the binary code of its own value, so -10=10001010.
The inverse code is inverted bit by bit, noting that the sign bit remains unchanged, so -10=11110101.
The complement adds one to the inverse, and -10=11110110.
Advantages and disadvantages of the original code
Simple and intuitive. For example, to represent a number in 8-bit binary, the original code for +11 is 00001011, and the original code for -11 is 10001011.
The original code cannot take part in arithmetic directly, and it may be wrong. For example, in math, 1 + (-1) = 0, and in binary 00000001 + 10000001 = 10000010, converted to decimal -2, obviously wrong.
So the sign bit of the original code can’t be directly involved in the operation, it must be separated from the other bits, which increases the hardware overhead and complexity.