Original code, inverse code, complement code

Original code, inverse code, complement code##

1) How to calculate the complement?
Rules:
positive number: original code = inverse code = complement code
Negative number : inverse code = sign bit remains unchanged, other bits are negated
Complement code = inverse code +
1 Original code of 1: 0000 0000 0000 0001
-1 original code: 1000 0000 0000 0001
-1's complement: 1111 1111 1111 1110
-1's complement: 1111 1111 1111 1111
Recalculate -1+1 result

1111 1111 1111 1111
0000 0000 0000 0001

0000 0000 0000 0000

2) Convert back to the original code from the complement code The rules for the conversion of the original code from the
negative complement code:

The original code = the sign bit of the complement code remains unchanged –> the data bit is inverted –> the tail +
1 -1's complement: 1111 1111 1111 1111
negation: 1000 0000 0000 0000
-1 The original code: 1000 0000 0000 0001
[Understand 】
Subtraction can be calculated by addition, just design an adder. Complementary code is used when computing. 2-1 = 2+(-1)=0000 0000 0000 0010 +1111 1111 1111 1111

[Understanding]
Why use the original code, the complement code and the complement code Since the original code is directly recognized by the human brain and used to calculate the representation, why are there still the complement code and the complement code? First of all, because the human brain can know the first code The bit is the sign bit. When calculating, we will choose the corresponding addition and subtraction according to the sign bit, but for the computer, the addition and subtraction multipliers are already the most basic operations, and the design should be as simple as possible. The computer's ability to identify the "sign bit" obviously complicates the basic circuit design of the computer! So people came up with a way to include the sign bit in the operation. We know that subtracting a positive number is equivalent to adding a negative number according to the algorithm, that is: 1-1 = 1 + (-1) = 0 , so the machine can only have Addition without subtraction, so the design of computer operations is simpler. So people began to explore ways to involve the sign bit in the operation, and only keep the addition method

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325497270&siteId=291194637