Logic gates can be configured in such a way that they perform meaningful logical or mathematical operation.
Adding binary numbers.
An XOR and an AND gate can be configured to compute a sum of two binary numbers. As a refresher, here are the first ten values in decimal and binary.
Adding two binary numbers by hand will yield:
Ignoring the carry-over number, the Truth Table for Exclusive OR emerges:
|A||B||A ⊕ B|
Only focusing on the carry-over number, the Truth Table for AND emerges:
|A||B||A ⋀ B|
The complete Truth Table for adding two numbers becomes:
|A||B||A ⊕ B||A ⋀ B||A + B|
This can be expressed in with the following circuit.
Click the buttons next to the A and B labels to represent 1 (one) or 0 (zero). Black represents 0 (zero) and orange represents 1 (one).
While the Half-Adder accepts two values: A and B and returns two values: Sum and Carry. A Full-Adder accepts A and B as before but also the Carry from a previous calculation. This circuit is a some what more complicated but still simple enough for you to follow the orange anf black lines.
Half-Adder and any number of Full-Adders can be chained together to compute a larger value.
This interactive allows for adding of two 4-bit numbers. The result is stored in a 4-bit number as well. Toggle the blue circles to indicate 1 or 0 values. Pay special attention to the carry-bit that goes from one adder to the other from right to left when applicable.
Ayx + Byx + Cyx + Dyx