Logic gates can be combined to produce more complex functions. They can also be combined to substitute one type of gate for another.
For example to produce an output Q which is true only when input A is true and input B is false, as shown in the truth table on the right, we can combine a NOT gate and an AND gate like this:
Input A | Input B | Output Q |
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 1 |
1 | 1 | 0 |
Q = A AND NOT B