Negative number original code inverse code complement arithmetic formula

Original code inverse code complement formula and relationship

Original code inverse code complement formula and relationship are as follows:

Original code: the highest bit of the binary number indicates the sign bit, 0 indicates a positive number, 1 indicates a negative number, and the rest of the bits indicate the magnitude of the value.

Inverse code: the inverse code of a positive number is the same as the original code, and the inverse code of a negative number is the inverse of each bit of its original code except the sign bit.

Complement: the complement of a positive number is the same as the original code, and the complement of a negative number is the addition of 1 to its inverse.

Calculation formula:

Relationships:

The conversion relationship between the original code, inverse code, and complement is fixed, and it can be converted by the formula.

In computers, the complement is often used to represent signed integers because it simplifies the implementation of addition and subtraction.

When performing addition and subtraction operations, you can add the complements of two numbers and convert the resultant complements to the original code to get the correct result.

Original to Inverse: The inverse of a negative number is the inverse of each bit of its original code except the sign bit.

Inverse code to original code: the original code of negative number is to invert all the bits of its inverse code except the sign bit.

Inverse to complement: the complement of a negative number is the inverse of its inverse plus 1.

Complement to inverse: the inverse of a negative number is the complement minus 1.

Complement to prime: the prime of a negative number is the complement minus 1, and then inverted in all but the sign bit.

When performing bitwise operations, the result of the original, inverse, and complement are the same because bitwise operations involve only the magnitude of the value, not the sign bit.

In computers, the complement is usually used to represent signed integers because it avoids the occurrence of two zeros, +0 and -0, as well as overflow.

When performing multiplication, you need to multiply the complements of two numbers and then convert the resultant complement to the original code to get the correct result.

In short, the original code, the inverse code, the complement is the computer to represent the three ways of signed integers, they have a fixed conversion relationship between them, according to the need to convert each other. In practice, usually use the complementary code to represent the signed integers, because the complementary code can simplify the implementation of addition and subtraction, to avoid the occurrence of two 0’s, but also to avoid the occurrence of overflow.

how to calculate the negative decimal original code, complement, inverse code and shift code, such as (-0.3125) decimal

The first decimal point indicates positive or negative, negative 1, first regardless of positive or negative, the integer part is 0 do not have to seek, the decimal part of the 0.3125 * 2 = 0.625, the integer part of the 0, the second decimal point is 0, and then calculate the 0.625 * 2 = 1.1.25, the integer part is 1, the second digit after the decimal point is 1, remove the integer 1,0.25*2=0.5, the integer part is 0, the third digit is 0,0.5.*2=1, the last digit is 1, the original code (1.0101). (Check that 2^-2+2^-4=0.25+0.0625=0.3125). For negative numbers, the inverse code is the original code inverted (1.1010), and for negative numbers, the complement is the original code inverted + 1 (1.1011), and there is no shifting code for decimals.

How to find the original, inverse, and complement of a positive or negative number? For example, +5

In computers, there is no original or inverse code, just the complement, which represents positive and negative numbers.

The significance of using the complement: you can convert subtraction, or negative numbers, into addition. Thus simplifying the hardware of the computer.

——— —-

For example, in a clock, the period of one revolution of the hour hand is 12 hours.

To dial 3 hours backwards, you can replace it with 9 hours forward.

9, is the complement of -3.

Calculation: 12-3=9.

——- —–

For example, limited to two decimal digits (0 to 99), the period is 100.

Subtracting one, then, can be replaced by +99.

24-1=23

24+99=(1)23

Ignoring rounding, with both algorithms, the result is the same.

So 99 is the complement of -1.

For the complements of other negative numbers, you can find your own!

——— —-

Binary is used in computers, and the complement, renamed [complement].

The common eight-bit binary is: 00000000~11111111.

They represent decimal: 0~255, and the period is 256.

The -1, then, can be replaced by 255 = 11111111.

So: the complement of -1, is 1111111111 = 255.

Similarly: the complement of -2, is 11111110 = 254.

Continuing: the complement of -3, is 1111111101 = 253.

.

.

Finally: -128, the complement of which is 10,000,000 = 128.

Formula: complement of a negative number = 256 + this negative number.

Positive numbers, direct arithmetic can be done without requiring the complement.

It can also be said that the positive numbers themselves are complements.

——— —-

Applications of the complement, e.g., 7-3 = 4.

The procedure for calculating with the complement is as follows:

7’s complement = 00000111

– The complement of 3 = 11111101

– Sum —— ——-

yields (1) 00000100 = 4’s complement

Discard the rounding and keep only the eight bits as the result.

——— —-

Original and inverse codes, useless. In computers, they are simply not there.