### Logic Gates & Truth Tables #### Basic Gates - **AND Gate** - Symbol: A · B - Truth Table: | A | B | Y | |---|---|---| | 0 | 0 | 0 | | 0 | 1 | 0 | | 1 | 0 | 0 | | 1 | 1 | 1 | - **OR Gate** - Symbol: A + B - Truth Table: | A | B | Y | |---|---|---| | 0 | 0 | 0 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 1 | - **NOT Gate (Inverter)** - Symbol: $\bar{A}$ or A' - Truth Table: | A | Y | |---|---| | 0 | 1 | | 1 | 0 | #### Universal Gates - **NAND Gate** - Symbol: $\overline{A \cdot B}$ - Truth Table: | A | B | Y | |---|---|---| | 0 | 0 | 1 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 0 | - **NOR Gate** - Symbol: $\overline{A + B}$ - Truth Table: | A | B | Y | |---|---|---| | 0 | 0 | 1 | | 0 | 1 | 0 | | 1 | 0 | 0 | | 1 | 1 | 0 | #### Special Gates - **XOR Gate (Exclusive OR)** - Symbol: $A \oplus B = A\bar{B} + \bar{A}B$ - Truth Table: | A | B | Y | |---|---|---| | 0 | 0 | 0 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 0 | - **XNOR Gate (Exclusive NOR)** - Symbol: $A \odot B = AB + \bar{A}\bar{B}$ - Truth Table: | A | B | Y | |---|---|---| | 0 | 0 | 1 | | 0 | 1 | 0 | | 1 | 0 | 0 | | 1 | 1 | 1 | ### Adders #### Half Adder (HA) - Adds two single binary digits (A, B) - Outputs: Sum (S), Carry (C) - Expressions: - $S = A \oplus B$ - $C = A \cdot B$ - Truth Table: | A | B | S | C | |---|---|---|---| | 0 | 0 | 0 | 0 | | 0 | 1 | 1 | 0 | | 1 | 0 | 1 | 0 | | 1 | 1 | 0 | 1 | #### Full Adder (FA) - Adds three single binary digits (A, B, Carry-in $C_{in}$) - Outputs: Sum (S), Carry-out ($C_{out}$) - Expressions: - $S = A \oplus B \oplus C_{in}$ - $C_{out} = (A \cdot B) + (C_{in} \cdot (A \oplus B))$ - Alternatively: $C_{out} = AB + AC_{in} + BC_{in}$ - Truth Table: | A | B | $C_{in}$ | S | $C_{out}$ | |---|---|----------|---|-----------| | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 1 | 1 | 0 | | 0 | 1 | 0 | 1 | 0 | | 0 | 1 | 1 | 0 | 1 | | 1 | 0 | 0 | 1 | 0 | | 1 | 0 | 1 | 0 | 1 | | 1 | 1 | 0 | 0 | 1 | | 1 | 1 | 1 | 1 | 1 | ### Subtractors #### Half Subtractor (HS) - Subtracts two single binary digits (A, B) - Outputs: Difference (D), Borrow (B) - Expressions: - $D = A \oplus B$ - $B = \bar{A} \cdot B$ - Truth Table: | A | B | D | B | |---|---|---|---| | 0 | 0 | 0 | 0 | | 0 | 1 | 1 | 1 | | 1 | 0 | 1 | 0 | | 1 | 1 | 0 | 0 | #### Full Subtractor (FS) - Subtracts three single binary digits (A, B, Borrow-in $B_{in}$) - Outputs: Difference (D), Borrow-out ($B_{out}$) - Expressions: - $D = A \oplus B \oplus B_{in}$ - $B_{out} = (\bar{A} \cdot B) + (B_{in} \cdot (\overline{A \oplus B}))$ - Alternatively: $B_{out} = \bar{A}B + \bar{A}B_{in} + BB_{in}$ - Truth Table: | A | B | $B_{in}$ | D | $B_{out}$ | |---|---|----------|---|-----------| | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 1 | 1 | 1 | | 0 | 1 | 0 | 1 | 1 | | 0 | 1 | 1 | 0 | 1 | | 1 | 0 | 0 | 1 | 0 | | 1 | 0 | 1 | 0 | 0 | | 1 | 1 | 0 | 0 | 0 | | 1 | 1 | 1 | 1 | 1 | ### Encoders - Converts $2^n$ input lines to n output lines. - Only one input line is active at any time. #### 8-to-3 Encoder - Inputs: $I_0, I_1, ..., I_7$ - Outputs: $Y_2, Y_1, Y_0$ - Expressions: - $Y_0 = I_1 + I_3 + I_5 + I_7$ - $Y_1 = I_2 + I_3 + I_6 + I_7$ - $Y_2 = I_4 + I_5 + I_6 + I_7$ - Truth Table (Simplified - assumes only one input is high at a time): | $I_7$ | $I_6$ | $I_5$ | $I_4$ | $I_3$ | $I_2$ | $I_1$ | $I_0$ | $Y_2$ | $Y_1$ | $Y_0$ | |-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------| | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | #### Logic Diagram A logic diagram for an 8-to-3 encoder would consist of three OR gates, one for each output ($Y_0, Y_1, Y_2$). - The $Y_0$ OR gate would have inputs $I_1, I_3, I_5, I_7$. - The $Y_1$ OR gate would have inputs $I_2, I_3, I_6, I_7$. - The $Y_2$ OR gate would have inputs $I_4, I_5, I_6, I_7$. ### Decoders - Converts n input lines to $2^n$ output lines. - Only one output line is active at any time based on input combination. #### 2-to-4 Decoder (Example) - Inputs: $A_1, A_0$ - Outputs: $D_0, D_1, D_2, D_3$ - Expressions: - $D_0 = \bar{A_1} \bar{A_0}$ - $D_1 = \bar{A_1} A_0$ - $D_2 = A_1 \bar{A_0}$ - $D_3 = A_1 A_0$ - Truth Table: | $A_1$ | $A_0$ | $D_0$ | $D_1$ | $D_2$ | $D_3$ | |-------|-------|-------|-------|-------|-------| | 0 | 0 | 1 | 0 | 0 | 0 | | 0 | 1 | 0 | 1 | 0 | 0 | | 1 | 0 | 0 | 0 | 1 | 0 | | 1 | 1 | 0 | 0 | 0 | 1 | ### Multiplexers (MUX) - Selects one of $2^n$ input data lines and routes it to a single output line. - Selection is controlled by n select lines. #### 4-to-1 Multiplexer - Data Inputs: $I_3, I_2, I_1, I_0$ - Select Inputs: $S_1, S_0$ - Output: Y - Expression: $Y = \bar{S_1}\bar{S_0}I_0 + \bar{S_1}S_0I_1 + S_1\bar{S_0}I_2 + S_1S_0I_3$ - Truth Table: | $S_1$ | $S_0$ | Y | |-------|-------|-------| | 0 | 0 | $I_0$ | | 0 | 1 | $I_1$ | | 1 | 0 | $I_2$ | | 1 | 1 | $I_3$ | ### Demultiplexers (DEMUX) - Takes a single input data line and routes it to one of $2^n$ output lines. - Selection is controlled by n select lines. #### 1-to-4 Demultiplexer (Example) - Data Input: D - Select Inputs: $S_1, S_0$ - Outputs: $Y_0, Y_1, Y_2, Y_3$ - Expressions: - $Y_0 = D \cdot \bar{S_1}\bar{S_0}$ - $Y_1 = D \cdot \bar{S_1}S_0$ - $Y_2 = D \cdot S_1\bar{S_0}$ - $Y_3 = D \cdot S_1S_0$ - Truth Table: | $S_1$ | $S_0$ | $Y_0$ | $Y_1$ | $Y_2$ | $Y_3$ | |-------|-------|-------|-------|-------|-------| | 0 | 0 | D | 0 | 0 | 0 | | 0 | 1 | 0 | D | 0 | 0 | | 1 | 0 | 0 | 0 | D | 0 | | 1 | 1 | 0 | 0 | 0 | D | ### Karnaugh Maps (K-Map) - Graphical method to simplify Boolean expressions. - Adjacent cells (differing by only one variable) can be grouped to eliminate variables. #### 2-Variable K-Map | | $\bar{B}$ | B | |---|-----------|---| | $\bar{A}$ | $m_0$ | $m_1$ | | A | $m_2$ | $m_3$ | #### 3-Variable K-Map | | $\bar{B}\bar{C}$ | $\bar{B}C$ | $BC$ | $B\bar{C}$ | |-----|-------------------|------------|------|------------| | $\bar{A}$ | $m_0$ | $m_1$ | $m_3$ | $m_2$ | | A | $m_4$ | $m_5$ | $m_7$ | $m_6$ | #### 4-Variable K-Map | | $\bar{C}\bar{D}$ | $\bar{C}D$ | $CD$ | $C\bar{D}$ | |-----|-------------------|------------|------|------------| | $\bar{A}\bar{B}$ | $m_0$ | $m_1$ | $m_3$ | $m_2$ | | $\bar{A}B$ | $m_4$ | $m_5$ | $m_7$ | $m_6$ | | $AB$ | $m_{12}$ | $m_{13}$ | $m_{15}$ | $m_{14}$ | | $A\bar{B}$ | $m_8$ | $m_9$ | $m_{11}$ | $m_{10}$ | #### Grouping Rules - Groups must be powers of 2 (1, 2, 4, 8, 16...). - Groups can be horizontal, vertical, or wrap around edges. - Groups should be as large as possible. - Cover all '1's in the map. - Overlapping groups are allowed.