0

I've been stuck on this question for a while now:

Show mathematically that two integers that have a sum of zero have one’s complement representations that are bit-complementary.

cinos
  • 117
  • 2
  • 8

1 Answers1

1

Here is a simple proof and a counter example:

One's complement representation by definition represents negative values with bit-complement. In other words -n is represented as ~n. If any two integers have a sum of zero, either they are both zero or one is the opposite of the other.

  • if they are both zero, they do not necessarily have one’s complement representations that are bit-complementary.
  • if they are opposite of each other and non-zero, then yes, they are bit-complementary of one another.
chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • I understand your proof and it does make sense, but I'm not sure how I can show mathematically: 5 + (-5) = 0 5 = 5 0101 = 0101 1010 (one's complement) = 1010 (one's complement) I'm pretty sure this is completely wrong but it's where I'm at right now... Thank you very much btw! – cinos Feb 16 '20 at 22:17
  • @cinos: There is not much to show mathematically. By definition, if the binary representation of a positive x is some string of bits s, then the one’s complement representation of −x is ~s (the string of bits in which each bit is the complement of the corresponding bit in s). So, for numbers other than zero, x and −x are **defined** to have complementary bit representations. – Eric Postpischil Feb 16 '20 at 22:23
  • @EricPostpischil ahhh I understand it now, thank you very much for your time! – cinos Feb 16 '20 at 22:26
  • @cinos: note however that `0+0=0` is a counter-example. – chqrlie Feb 16 '20 at 22:36