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
Adder–subtractor
(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!
==Construction== [[Image:4-bit ripple carry adder-subtracter.svg|thumb|400px|A 4-bit ripple-carry adder–subtractor based on a 4-bit adder that performs [[two's complement]] on ''A'' when {{nowrap|1=''D'' = 1}} to yield {{nowrap|1=''S'' = ''B'' − ''A''}}.]] Having an ''n''-bit adder for ''A'' and ''B'', then {{nowrap|1=''S'' = ''A'' + ''B''}}. Then, assume the numbers are in [[two's complement]]. Then to perform {{nowrap|''B'' − ''A''}}, two's complement theory says to invert each bit of ''A'' with a [[NOT gate]] then add one. This yields {{nowrap|1=''S'' = ''B'' + {{overline|''A''}} + 1}}, which is easy to do with a slightly modified adder. By preceding each ''A'' input bit on the adder with a 2-to-1 [[multiplexer]] where: * Input 0 (''I''<sub>0</sub>) is ''A'' * Input 1 (''I''<sub>1</sub>) is {{overline|''A''}} that has control input ''D'' that is also connected to the initial carry, then the modified adder performs * addition when {{nowrap|1=''D'' = 0}}, or * subtraction when {{nowrap|1=''D'' = 1}}. This works because when {{nowrap|1=''D'' = 1}} the ''A'' input to the adder is really {{overline|''A''}} and the carry in is 1. Adding ''B'' to {{overline|''A''}} and 1 yields the desired subtraction of {{nowrap|''B'' − ''A''}}. A way you can mark number ''A'' as positive or negative without using a multiplexer on each bit is to use an [[XOR gate]] to precede each bit instead. * The first input to the XOR gate is the actual input bit * The second input for each XOR gate is the control input ''D'' This produces the same [[truth table]] for the bit arriving at the adder as the multiplexer solution does since the XOR gate output will be what the input bit is when {{nowrap|1=''D'' = 0}} and the inverted input bit when {{nowrap|1=''D'' = 1}}.
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)