E
E
Eugene2021-10-13 10:15:19
Informatics
Eugene, 2021-10-13 10:15:19

What is the difference between operation algorithms in complementary and inverse codes?

I remember that the return code is !direct, and the complementary code is !direct + 1 to the least significant bit. What will be the difference in the algorithms of arithmetic operations (addition, multiplication, etc.), if the numbers are given in the inverse code or additional code.
As far as I remember, the difference is in the addition operation, when 1 is added to the lower one during overflow, but not in the additional one, correct if not.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-10-13
@coi175

Reverse code: !x = 2^n-1 - x.
Complementary code - !x+1 = 2^n - x.
In two's complement code, the number -x is written as 2^nx. Therefore, it can simply be added / subtracted / multiplied - the extra 2 ^ n does not fit into the capacity of the variable and will simply be ignored.
In the reverse code, you have an extra -1 that needs to be compensated. add when subtracting, subtract when adding, and add a factor when multiplying.
Also, there is no way to write 2^(n-1) in the reverse code, because the number 0 can be represented 2 times as 00000000 and 100000000.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question