No, I can not solve this problem. Nothing comes to mind at all. :(

You have two 16-bit registers R1 and R2, and the addition to 2 is used to represent negative numbers. The register R1 stores the number X which is not equal to zero. You wrote down the value of -X in the R2 register and it turned out that the values ​​in the R1 and R2 registers are equal. Find the number X.

Task from here .

1 answer 1

When using a complement of up to two to represent negative numbers, half of the representable numbers in a fixed-bit register will be negative, and half non-negative. And since zero belongs to non-negative numbers, it turns out that there can be one more representable negative numbers than positive positive ones. That is, there is such a negative number, the inverse of which is not represented in the register of the same bitness. Actually, this number X=1000000000000000 2 and will be the only candidate for the condition -X=X, X≠0 . The fact that this number satisfies the condition can be easily verified by performing the conversion operation according to the rules of addition to two: reverse all bits ( 0111111111111111 2 ) and add one ( 1000000000000000 2 ).

  • Excellent explanation, everything is clear. The only thing for some reason does not pass the test. A link to the site with the test added to the question. - faoxis
  • @faoxis I enter -32768 and it shows me that the answer is correct. - PetSerAl
  • Hurried and introduced in the binary system ... - faoxis 6:39 pm