Adding the Two Numbers
We now add the two numbers:
1101(−3)+0100(+4)
= 10001(Carry 1 out)
Here, the result is 10001. Since we’re working with 4-bit numbers, we ignore the extra carry bit on the left (because we’re adding two 4-bit numbers, the result should fit in 5 bits).
So, the final result is 0001, which equals +1 in decimal.
Why Do We Ignore the Extra Bit?
In binary addition, if the result has more bits than the original number of bits, you simply ignore the carry. This is why we ignore the extra leftmost bit, and the final result is 0001 (which is +1).
This process happens because, in two's complement, the range of values for a 4-bit number is -8 to +7. If you get a result that exceeds this range (like a 5th bit), it means the value overflows. But in this case, the overflow bit indicates a carry, and it’s ignored.
Extra Info : Two's Complement Interpretation (for Negative Numbers)
When interpreting a two's complement number, you check the MSB:
- If the MSB is 0, the number is positive.
- If the MSB is 1, the number is negative, and you need to invert the bits and add 1 to get the positive equivalent.
For example:
- 111: The MSB is 1, so it's negative. Inverting the bits: 000. Adding 1 gives 001, which is 1. So, 111 represents -1.
- 011: The MSB is 0, so it's positive. 011 is just +3 in decimal.
Can You Directly Add/Subtract Two's Complement Numbers?
Yes, you can directly add or subtract two's complement numbers. The beauty of two's complement is that it allows you to perform addition and subtraction without worrying about whether the numbers are positive or negative. The result will automatically be correct, including handling overflow and the sign of the number.
Summary :
- Two's complement allows you to handle negative numbers using the MSB.
- For addition, just add the numbers like normal binary addition and ignore any overflow beyond the original bit width (4-bits, 8-bits, etc.).
- Conversion between positive and negative numbers is handled by inverting the bits and adding 1 for negative numbers.
- The MSB (most significant bit) tells you whether the number is positive or negative:
- 0 means positive.
- 1 means negative (and you need to take the two's complement to find its magnitude).