Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 3
    I like this answer! Explains how taking 2s complement and adding one works. Commented Jun 7, 2017 at 8:37
  • I like this answer as well. Especially where you show how the negative number is figured. Here I thought the whole number was inverted, not just the MSB and then added back the other weighted values. Thank you, this solved my brain block Commented Jul 9, 2017 at 9:18
  • Good job mentioning the oddball number that doesn't have an inverse. But what do we do about this? Do we just set the overflow flag if someone tries to invert it? Commented Jul 12, 2017 at 19:56
  • 2
    While other answers focus on the "how", this answer leads us gently with the "why". It helped me. Thanks! Commented Oct 21, 2018 at 15:48
  • If a number ends with 11000...000, inverting it will yield 01000...000. Two's-complement notation is based on the idea that all digits to the left of the leftmost represented digit should have the same value as that digit, but when inverting a number whose representation is 1000...000, that won't be true. Commented Aug 5, 2019 at 21:45