Note: for the 2-bit adder and everything after, we will assume there is no carry in from anything right of the ones column.
(assuming no carry in into the ones).
This means for the 2-bit adder, there will be 4 inputs and 3 outputs:
- Ex 11+10=101
The carry out from the ones goes directly into the carry in of the twos.
We will display the carry out from the twos (which is actually the fours column, right!)
For this circuit, once again we are just using positive binary numbers, not 2s compliment.
Note: that we are not using an if ... elseif ... statement any more.
If we were, we would now need 16 of them. Clearly this is a bad idea.
By using loops, we can get the same effect of adding all the digits, but it is much smaller code.
Note: from the image below, you have to be careful what pins you use, since some pins have several uses. DO NOT use any pin that is also used for the LEDs or buttons or it will mess with your display and code.