Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Two's complement
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Subtraction from 2<sup>''N''</sup>=== The sum of a number and its ones' complement is an {{mvar|N}}-bit word with all 1 bits, which is (reading as an unsigned binary number) {{math|2<sup>''N''</sup> β 1}}. Then adding a number to its two's complement results in the {{mvar|N}} lowest bits set to 0 and the carry bit 1, where the latter has the weight (reading it as an unsigned binary number) of {{math|2<sup>''N''</sup>}}. Hence, in the unsigned binary arithmetic the value of two's-complement negative number {{math|''x''*}} of a positive {{mvar|x}} satisfies the equality {{math|1=''x''* = 2<sup>''N''</sup> β ''x''}}.{{efn|For {{math|1=''x'' = 0}} we have {{math|1=2<sup>''N''</sup> β 0 = 2<sup>''N''</sup>}}, which is equivalent to {{math|1=0* = 0}} modulo {{math|2<sup>''N''</sup>}} (i.e. after restricting to {{mvar|N}} least significant bits).}} For example, to find the four-bit representation of β5 (subscripts denote the [[radix|base of the representation]]): {{block indent|{{math|1=''x'' = 5<sub>10</sub>}} therefore {{math|size=120%|1=''x'' = 0101<sub>2</sub>}}}} Hence, with {{math|1=''N'' = 4}}: {{block indent|{{math|1=''x''* = 2<sup>''N''</sup> β ''x'' = 2<sup>4</sup> β 5<sub>10</sub> = 16<sub>10</sub> β 5<sub>10</sub> = 10000<sub>2</sub> β 0101<sub>2</sub> = 1011<sub>2</sub>}}}} The calculation can be done entirely in base 10, converting to base 2 at the end: {{block indent|{{math|1=''x''* = 2<sup>''N''</sup> β ''x'' = 2<sup>4</sup> β 5<sub>10</sub> = 11<sub>10</sub> = 1011<sub>2</sub>}}}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)