Logic Gates Overview Logic gates are fundamental building blocks of digital circuits, performing basic logical operations. Basic Gates: AND, OR, NOT Universal Gates: NAND, NOR (can implement any basic gate) Derived Gates: XOR, XNOR AND Gate (IC 7408) Performs logical multiplication. Output is high only if all inputs are high. Q A B Truth Table A B A$\cdot$B 0 0 0 0 1 0 1 0 0 1 1 1 OR Gate (IC 7432) Performs logical addition. Output is high if any input is high. A B out Truth Table A B A+B 0 0 0 0 1 1 1 0 1 1 1 1 NOT Gate (IC 7404) Inverts the input. Output is high if input is low, and vice versa. A Q Truth Table A $\bar{A}$ 0 1 1 0 NAND Gate (IC 7400) Output is low only if all inputs are high (AND + NOT). A B Y Truth Table A B $\overline{A \cdot B}$ 0 0 1 0 1 1 1 0 1 1 1 0 NOR Gate (IC 7402) Output is low if any input is high (OR + NOT). A B Y Truth Table A B $\overline{A+B}$ 0 0 1 0 1 0 1 0 0 1 1 0 XOR Gate (IC 7486) Output is high if an odd number of inputs are high (exclusive OR). A B Y Truth Table A B A$\oplus$B 0 0 0 0 1 1 1 0 1 1 1 0 Boolean Algebra Theorems Commutative Law Addition: $A + B = B + A$ Multiplication: $A \cdot B = B \cdot A$ Associative Law Addition: $A + (B + C) = (A + B) + C$ Multiplication: $A \cdot (B \cdot C) = (A \cdot B) \cdot C$ Distributive Law $A \cdot (B + C) = (A \cdot B) + (A \cdot C)$ $A + (B \cdot C) = (A + B) \cdot (A + C)$ De Morgan's Theorems $\overline{A \cdot B} = \bar{A} + \bar{B}$ $\overline{A + B} = \bar{A} \cdot \bar{B}$ Half Adder Adds two single binary digits (A and B) and outputs a sum (S) and a carry (C). Sum: $S = A \oplus B$ Carry: $C = A \cdot B$ Truth Table A B SUM CARRY 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 Half Subtractor Subtracts one binary digit from another and outputs a difference (D) and a borrow (B). Difference: $D = A \oplus B$ Borrow: $B = \bar{A} \cdot B$ Truth Table A B DIFFERENCE BORROW 0 0 0 0 0 1 1 1 1 0 1 0 1 1 0 0 Full Adder Adds three single binary digits (A, B, and Carry-in $C_{in}$) and outputs a sum (S) and a carry (C). Sum: $S = (A \oplus B) \oplus C_{in}$ Carry: $C = (A \cdot B) + (C_{in} \cdot (A \oplus B))$ Truth Table A B $C_{in}$ SUM CARRY 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 Full Subtractor Subtracts three single binary digits (A, B, and Borrow-in $B_{in}$) and outputs a difference (D) and a borrow (B). Difference: $D = (A \oplus B) \oplus B_{in}$ Borrow: $B = (\bar{A} \cdot B) + (B_{in} \cdot (\overline{A \oplus B}))$ Truth Table A B $B_{in}$ DIFFERENCE BORROW 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 4-bit Binary Adder/Subtractor (IC 7483) Performs addition or subtraction of two 4-bit binary numbers depending on a mode select input (S). If $S=0$, performs Addition: $X+Y$ If $S=1$, performs Subtraction: $X + (\text{1's complement of } Y) + 1$ (2's complement arithmetic) Multiplexer (MUX) A data selector that routes one of $2^N$ input lines to a single output line based on $N$ select lines. 4:1 MUX (IC 7411, 7432, 7404) Selects one of four inputs ($D_0, D_1, D_2, D_3$) based on two select lines ($S_1, S_0$). Output $Y = \bar{S_1}\bar{S_0}D_0 + \bar{S_1}S_0D_1 + S_1\bar{S_0}D_2 + S_1S_0D_3$ Function Table (4:1 MUX) $S_1$ $S_0$ Output Y 0 0 $D_0$ 0 1 $D_1$ 1 0 $D_2$ 1 1 $D_3$ Encoder Converts information from $2^N$ input lines to an $N$-bit binary code output. Only one input can be active at a time. Octal to Binary Encoder (8:3) Converts an 8-line input (representing digits 0-7) to a 3-bit binary output. Truth Table (Octal to Binary Encoder) Inputs ($Y_0 - Y_7$) Outputs ($A_2 A_1 A_0$) $Y_0$ $Y_1$ $Y_2$ $Y_3$ $Y_4$ $Y_5$ $Y_6$ $Y_7$ $A_2$ $A_1$ $A_0$ 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 Decoder Converts an $N$-bit binary input code to $2^N$ unique output lines. Only one output is active at a time. 2 to 4 Decoder Converts a 2-bit input (A, B) to one of four outputs ($Y_0 - Y_3$). Truth Table (2 to 4 Decoder with Enable) Enable (E) A B $Y_0$ $Y_1$ $Y_2$ $Y_3$ 0 X X 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 0 0 1 BCD Adder Adds two BCD digits and an input carry to produce a BCD sum digit and an output carry. If 4-bit sum is $\le 9$, it's a valid BCD number. If 4-bit sum is $> 9$ or if a carry is generated, it's an invalid BCD result. Add 6 (0110) to correct it. Magnitude Comparator (IC 7485) Compares two binary numbers (A and B) and determines their relative magnitudes: $A>B$, $A 2-bit Magnitude Comparator Compares two 2-bit numbers ($A_1 A_0$ and $B_1 B_0$). $A=B$: $(A_1 \odot B_1) \cdot (A_0 \odot B_0)$ (where $\odot$ is XNOR) $A>B$: $(A_1 \cdot \bar{B_1}) + ((A_1 \odot B_1) \cdot A_0 \cdot \bar{B_0})$ $A 3-bit Synchronous Up Counter Counts upwards from 0 to 7 (000 to 111) and then resets, synchronized by a common clock pulse. State Diagram 000 001 010 011 100 101 Truth Table (JK Flip-Flop Excitation) Q $Q_{t+1}$ J K 0 0 0 X 0 1 1 X 1 0 X 1 1 1 X 0 3-bit Synchronous Down Counter Counts downwards from 7 to 0 (111 to 000) and then resets, synchronized by a common clock pulse. State Diagram 000 111 110 101 100 011 Universal Shift Register A register capable of shifting data left or right, and performing parallel load, controlled by select inputs. Operation Modes $S_1$ $S_0$ Register Operation 0 0 No change 0 1 Shift right 1 0 Shift left 1 1 Parallel load