Machine-translated by Google. Questions are authored in English.
Top

Discussion

Bitwise can be used to reverse a sign of a number.

  • A.Yes
  • B.No

Answer: B

Correct answer: No

Negation in two's complement is ~x + 1, and that + 1 is ordinary addition, not a bitwise operation. Inverting the bits alone gives \( -x - 1 \), which is one short of the answer.

The reason is that bitwise operators work on each position independently and have no mechanism to propagate a carry, and changing a number's sign requires exactly that carry. XOR with a sign-bit mask flips the sign bit of a floating-point value, but that is a property of the IEEE format rather than of integer arithmetic.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.