### How to calculate the inverse complement of the original code

The calculation of the inverse complement of the original code is as follows:

Original code

1: the word length is 8, and the sign bit (the first one) is 0, which means a positive number; the sign bit (the first one) is 1, which means a negative number.

2: 00000001 means positive 1; 10000001 means negative 1.

Two, inverse code

1: positive number, the inverse code is the same as the original code. The original code and inverse code of positive 1 is 00000001.

2: Negative number, the sign bit remains unchanged and other bits are inverted. The inverse code of negative 1 is 11111110.

Three, complementary code

1: positive number, the complementary code is the same as the original code. The complement of positive 1 is 00000001.

2: Negative numbers, the complement is the inverse plus 1, the complement of negative 1 is 11111111.

3: The computer is using the complement in the calculation.

Four, shifted code

1: the sign bit of the complement is taken to be 10000001 for 1; the shifted code for minus 1 is 01111111.

Binary is a number system that is widely used in computing technology. Binary data is a number represented by two digits, 0 and 1. Its base is 2, and the rule of rounding is “two into one”, and the rule of borrowing is “borrowing one as two”, which was discovered by Leibniz, the 18th-century German master of mathematical philosophy. Current computer systems use what is essentially a binary system.

Data is stored in computers mainly in the form of complements. The binary in a computer is a very tiny switch, with ‘on’ for 1 and ‘off’ for 0. The invention and application of computers in the 20th century is known as one of the major symbols of the third technological revolution, because digital computers can only recognize and process data consisting of ‘0’ and ‘0’. Processing by ‘0’. ‘1’ strings of symbols.

The mode of operation is precisely binary. 19th-century Irish logician George Boole’s process of thinking about logical propositions translates into the use of the symbols ”0”. 1” of some kind of algebraic arithmetic, binary is a 2-bit system of progressions. 0, 1 is the basic operator. Because it only uses 0, 1 two digital symbols, very simple and convenient, easy to realize electronically.

### Computer original code inverse code complement how to calculate?

In computer systems, numerical values are always represented and stored as complements.

The complement, in fact, is a positive number that “operates in place of a negative number”.

With the use of the complement, there are no negative numbers in computers.

And with that: none of the subtraction operations exist either.

So, with the help of the complement, the computer only needs to be configured with an adder, and it can go all the way.

The purpose of using complementary codes is just that: to simplify the computer’s hardware.

And the original code, the inverse code, have no such function, so, in computers, they are not used at all.

So, the original code and the inverse code, can only be written on a piece of paper, in the computer, are not there.

——— ———- —

How is the complement (a positive number), a substitute for a negative number?

Look at the hour hand: 3 hours backwards can be replaced by 9 hours forwards, right?

Look at the trigonometric functions: -π/2, +3π/2, both of which also have the same function value.

The decimal numbers, if limited to only 2 digits, would be:

25-1=24

25+99=(one hundred)24

If you ignore rounding up by one hundred (10^2), +99 replaces -1.

Above. These positive numbers are the “complements of negative numbers”.

The formula for finding the complement is: complement (i.e., positive number) = negative number + period.

The positive numbers must be taken directly into the operation, without any further transformation.

That is to say: a positive number, by itself, is already a positive number; there is no complement to it.

——— ———- —

Computers use binary, the complement, which is called the “complement”.

The period of an 8-bit binary is: 2^8=256.

The 8-bit binary makes a total of 256 codes.

Use half of them (i.e., 128) to represent negative numbers: -1 to -128.

Then:

The complement of -1, is:-1+256=255=11111111 (binary ).

The complement of -2 is: -2+256=254=11111110.

.

The complement of -128, is: 128=10000000.

—— ———- —–

At this point, you can introduce the “Definition of the complement”:

When X>=0, [X]-complement[/X]-complement[/X]-complement[/X] is: 128=10000000. [X]-complement = X; zeros and positive numbers don’t need to be transformed.

When X<0, [X]-complement= X+2^n. n is the number of bits in the complement.

This is the universal formula.

There are also such formulas in more rigorous books, so go flip through them.

——— ———- —

Following the formula to find the complement is extremely easy, and you can still understand the meaning of the complement.

From the complement, it is also easy to find the value it represents.

Then, do not learn “the original code inverse code take the inverse plus one sign bit unchanged”.

Additionally, the original and inverse codes are one number less than the complement, and the inverse plus one is unusable.

Only those foreigners who are not good at math make these “spacing” tricks.

Actually, just knowing how to swap “complement and value” is enough.

——— ———-

The equation 5-7 = -2 is calculated by the computer using the eight-bit complement as follows:

5 =00000101

[-7] complement = 11111001

— Add up ——- —-

Get: (1) 11111110 = [-2]’s complement

Rounding off the rounding, the result, is correct.

### How do you calculate the original code of a number when its complement is known?

When the complement of a number is known, the original code of the number can be calculated by the following steps:

1, convert the complement to the original code:

Original code=complement+significant digit*2^n

Where the significant digit is the highest digit (sign digit is used to represent the plus and minus signs), and the numeric digits are calculated from the lowest digit.

2, the expression obtained is substituted into the formula for the conversion of the complementary code to the original code, where the sign bit is the highest bit (the sign bit is used to represent the plus or minus sign) and the numerical bit is calculated from the lowest bit.

3, solve the numerical part:

Transform the formula to get:

Numerical part=original code-complementary code

4, convert the numerical part to decimals:

Divide the numerical part by 2^n to get the corresponding number of decimal places.

5, shift the decimal point to the left by n digits to get the original code:

Original code=numeric part * 2^n + 0xnn (where nn is the first digit to the left of the decimal point)