A brief anti-code complement the original code of

The 8 bit value used herein relates to digital computing, and are based.


The original code, the inverted, complementary codes are binary computer representation of numbers


Original code

The most significant bit is the sign bit of the original code, wherein 1 represents -, + 0 for
the other bits represent the absolute value of the number

For example, we have represented a 8-bit binary numbers, the original code + 2 is 00000010, the original code is 10000010. -2
advantage primitive is simple and intuitive, but also the original code has a big drawback is not directly involved in computing, You may be wrong. Mathematically e.g. 2 + (- 2) = 0, while in binary 00000010 + 10000010 = 10000010, converted to decimal -2. Obviously wrong.

Inverted

Positive anti-code code is its original
negative is inverted on the basis of the original code, change the sign bit, the other bits bitwise

For example, the original code and the inverted 2 is 00000010; -2 original code is 10000010, 11111101 is inverted.
Inverted original code is typically used to request a transition twos complement or original code symbols by complement.
Appears inverted to solve the problem of the original code can not perform subtraction, but also lost the original code simple and intuitive advantages.
But there are still anti-code operation between the issue can not be negative. E.g. 11111110 (-1) +11111100 (-3) = 11111010 (-5)

Complement

Complement positive number is its original code
complement negative is that it's a plus-minus

127, for example, complement is 01111111, 10000001 complement -127.
We have the perfect complement appears to solve the shortcomings of the inverted, so the computer's complement subtraction is adding into the key code. The computer is based on a digital operation of complement.

to sum up

1. positive number of the original code, anti-code and complement the same.
2. The negative is the inverted complement plus 1, the inverted original code is bitwise, only the highest bit (sign bit) unchanged.
3. The computer digital calculation are based on complement.

Released four original articles · won praise 3 · Views 181

Guess you like

Origin blog.csdn.net/humblehunger/article/details/103450462