📚 Introduction
Learn how computers perform arithmetic operations on signed binary numbers using efficient 2's complement representation. This system simplifies both addition and subtraction using the same hardware!
🔤 Signed Number Representations
Signed-Magnitude Representation
The leftmost bit represents the sign (0 = positive, 1 = negative), and the remaining bits represent the magnitude.
Sign bit + Magnitude bits
Signed-2's Complement Representation
Negative numbers are obtained by taking the 2's complement of the positive number. This system is preferred because it simplifies arithmetic operations.
- Invert all bits (1's complement)
- Add 1 to the result
Why 2's Complement?
- Addition and subtraction use the same hardware
- No separate positive and negative zero
- Simpler overflow detection
- Natural extension of unsigned arithmetic
➕ Binary Addition (2's Complement)
Simple Procedure:
- Add the two numbers, including their sign bits
- Discard any carry out of the sign bit position
- The result is automatically in 2's complement form
Example 1: (+6) + (+13) = +19
Example 2: (-6) + (+13) = +7
➖ Binary Subtraction (2's Complement)
Subtraction is performed by converting it to addition:
Change the sign of the subtrahend and add!
Procedure for A - B:
- Take the 2's complement of B (subtrahend)
- Add it to A (minuend)
- Discard the carry out of the sign bit position
Example: (+7) - (+13) = -6
⚠️ Overflow Detection
When two signed n-bit numbers produce a sum requiring n+1 bits, overflow occurs.
- Two positive numbers sum to a negative result
- Two negative numbers sum to a positive result
If carry into sign bit ≠ carry out of sign bit → Overflow!
This can be implemented with an XOR gate for the two carry signals.
🧮 Interactive Calculator
Enter numbers and click Calculate to see the step-by-step solution!