Original code complement

2021-10-14 03:06:53

Complement code Is a kind of use Binary system A method of representing signed numbers , It's also a way to change the sign of a number , Often in Computer science Use in . The complement is defined as a binary number of signed bits .

The biggest advantage of complement system is that it can be used in addition or subtraction , There is no need to use different calculation methods because of the positive and negative of the number . Only one addition circuit can handle all kinds of signed addition , And subtraction can be represented by the complement of one number plus another , Therefore, as long as there is an addition circuit and a complement circuit, all kinds of signed addition and subtraction can be completed , It's quite convenient in circuit design .

Why complement 0 There is only one ？

 ` Truth value ` ` Original code ` ` Complement code ` `+0` `0000 0000` `0000 0000` `-0` `1000 0000` `0000 0000`
 `+0` `0.0000` `0.0000` `-0` `1.0000` `0.0000`

The relationship between complement and original code ： Complement code = The original code is reversed except for the sign bit +1（ The complement symbol bit can participate in the operation ）

Integers （0000 0000） Take the opposite ：0111 1111 Add 1:0000 0000

（1000 0000） Take the opposite ：1111 1111 Add 1:0000 0000（ Carry on 1 Be abandoned , Just don't take values anymore ）

Floating point numbers （0.0000） Take the opposite ：0.1111 Add 1:0.0000

（1.0000） Take the opposite ：1.1111 Add 1：0.0000

Why can an eight digit integer complement represent -128, Floating point numbers can represent -1？

 Truth value Original code Complement code +0 0000 0000 0000 0000 -0 1000 0000 0000 0000 1 0000 0001 0000 0001 2 0000 0010 0000 0010 … … … 127 0111 1111 0111 1111 -128 nothing 1000 0000 -127 1111 1111 1000 0001 -126 1111 1110 1000 0010 … … … -2 1000 0010 1111 1110 -1 1000 0001 1111 1111
-127-1=1000 0001-0000 0001=1000 0000

or -127-1=1000 0001+1111 1111=1000 0000（ Carry away ）

Because of the complement +0 and -0 Use the same number to represent , So leave a number to represent -128

 Truth value Original code Complement code +0 0.0000 0.0000 -0 1.0000 0.0000 1/16 0.0001 0.0001 1/8 0.0010 0.0010 3/16 0.0011 0.0011 1/4 0.0100 0.0100 5/16 0.0101 0.0101 3/8 0.0110 0.0110 7/16 0.0111 0.0111 1/2 0.1000 0.1000 … … … 15/16 0.1111 0.1111 1 nothing 1.0000 -15/16 1.1111 1.0001 … … … -3/8 1.0110 1.1010 -5/16 1.0101 1.1011 … … … -1/16 1.0001 1.1111
Floating point numbers are the same

https://chowdera.com/2021/10/20211002145822822W.html