## Micro Controller : Logical Components

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.

decimal | binary |

0 | 0 |

1 | 1 |

2 | 10 |

3 | 11 |

4 | 100 |

5 | 101 |

6 | 110 |

7 | 111 |

8 | 1000 |

9 | 1001 |

### Half-Adder.

Adding two binary numbers by hand will yield:

A | B | carry | sum | decimal | |

0 | + | 0 | - | 0 | 0 |

0 | + | 1 | - | 1 | 1 |

1 | + | 0 | - | 1 | 1 |

1 | + | 1 | 1 | 0 | 2 |

Ignoring the carry-over number, the Truth Table for Exclusive OR emerges:

A | B | A ⊕ B |

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 0 |

Only focusing on the carry-over number, the Truth Table for AND emerges:

A | B | A ⋀ B |

0 | 0 | 0 |

0 | 1 | 0 |

1 | 0 | 0 |

1 | 1 | 1 |

The complete Truth Table for adding two numbers becomes:

A | B | A ⊕ B | A ⋀ B | A + B |

0 | 0 | 0 | 0 | 00 |

0 | 1 | 0 | 1 | 01 |

1 | 0 | 0 | 1 | 01 |

1 | 1 | 1 | 0 | 10 |

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).

### Full-Adder

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.

## Chaining Adders

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.

## Multiplexer.

Ayx + Byx + Cyx + Dyx