Addition/Subtraction Conversion
Addition/Subtraction Conversion
What is Addition/Subtraction Conversion?
Addition/subtraction conversion is a technique in computer arithmetic where subtraction is performed using addition. This is achieved by representing negative numbers (typically in 2’s complement) and adding them to perform subtraction, simplifying hardware design.
Why Addition/Subtraction Conversion is Important
Hardware Simplicity: CPUs use a single adder circuit for both addition and subtraction, reducing complexity.
Efficiency: Eliminates the need for dedicated subtraction logic.
Standard in CPUs: 2’s complement-based subtraction is universal in modern processors.
Accuracy: Ensures consistent results for signed and unsigned arithmetic.
How Addition/Subtraction Conversion Works
Subtraction (
A - B
) is converted to addition (A + (-B)
).The negative number (
-B
) is represented in 2’s complement form.The CPU performs addition using the adder circuit.
Any overflow (carry-out) is ignored for signed numbers in 2’s complement.
Steps for Subtraction Using 2’s Complement
Write the binary representation of both numbers (
A
andB
).Find the 2’s complement of the subtrahend (
B
):Flip all bits (1’s complement).
Add 1 to the result.
Add the 2’s complement of
B
toA
.Ignore any carry-out (overflow) for the result.
Interpret the result:
If the most significant bit (MSB) is 0, the result is positive.
If the MSB is 1, the result is negative (convert to positive using 2’s complement if needed).
Example: Subtraction
Perform 7 - 4
(4-bit numbers):
Step 1:
7
=0111
,4
=0100
.Step 2: 2’s complement of
4
:1’s complement:
0100
→1011
.Add 1:
1011 + 1 = 1100
.
Step 3: Add:
0111 + 1100 = 10011
.Step 4: Ignore carry-out:
0011
(drop the 5th bit).Step 5: Result:
0011
=3
(positive, MSB = 0).
Example: Negative Result
Perform 4 - 7
(4-bit numbers):
Step 1:
4
=0100
,7
=0111
.Step 2: 2’s complement of
7
:1’s complement:
0111
→1000
.Add 1:
1000 + 1 = 1001
.
Step 3: Add:
0100 + 1001 = 1101
.Step 4: No carry-out, result:
1101
.Step 5: Result:
1101
(MSB = 1, negative).Convert to positive: 2’s complement of
1101
=0010 + 1 = 0011
=3
.So,
1101
=-3
.
Addition in 2’s Complement
For addition (
A + B
), no conversion is needed if both numbers are in 2’s complement.Simply add the binary numbers and ignore any carry-out.
Example:
3 + 2
(4-bit):3
=0011
,2
=0010
.Add:
0011 + 0010 = 0101
=5
.
Why 2’s Complement is Used
Single Zero: Unlike 1’s complement, 2’s complement has one zero (
0000
), avoiding ambiguity.No Extra Steps: Subtraction requires only addition, no end-around carry.
Signed Numbers: Handles both positive and negative numbers seamlessly.
Hardware Efficiency: Adder circuits work for both operations.
Where Addition/Subtraction Conversion is Used
ALU (Arithmetic Logic Unit): Performs arithmetic in CPUs using 2’s complement.
Compilers: Generate machine code for subtraction as addition.
Digital Systems: Calculators, embedded devices, and DSPs.
Programming: Handles signed integers in languages like C, Java.
Why It Matters in COA
Simplified Design: One adder circuit supports all arithmetic operations.
Performance: Faster execution by avoiding separate subtraction logic.
Standardization: 2’s complement is universal, ensuring compatibility.
Error Handling: Overflow detection is straightforward (e.g., check MSB).
Additional Insights
Overflow:
Occurs when the result exceeds the bit range (e.g.,
7 + 7
in 4-bit =1110
=-2
, incorrect).Detected when the carry-in and carry-out of the MSB differ.
Sign Bit: MSB indicates sign (0 = positive, 1 = negative).
Range (n-bit):
Minimum:
-2^(n-1)
(e.g.,-8
for 4-bit).Maximum:
2^(n-1) - 1
(e.g.,+7
for 4-bit).
Limitations:
Fixed bit length limits number range.
Overflow errors require careful handling in software.
1’s Complement Alternative:
Rarely used due to dual zeros and end-around carry.
Example:
7 - 4
needs extra step to add carry back.
Summary Table
Operation
Method
Key Step
Addition
Add numbers directly.
Ignore carry-out.
Subtraction
Convert to A + (-B)
using 2’s complement.
Add 2’s complement of subtrahend.
Example Breakdown: Mixed Operations
Perform 5 - 2 + 3
(4-bit):
Step 1:
5 - 2
:5
=0101
,2
=0010
.2’s complement of
2
:1101
.Add:
0101 + 1101 = 10010
→0011
=3
.
Step 2:
3 + 3
:3
=0011
,3
=0011
.Add:
0011 + 0011 = 0110
=6
.
Result:
0110
=6
.
Last updated