Logic Gates

Logic Gates

Logic gates are used to manipulate inputs in order to get a desired output, that’s slightly hard to get your head around but ‘truth tables’ make it way easier to understand.

There are 3 types of logic gate:

  • NOT
  • AND
  • OR

 

There are actually more logic gates, but these 3 are the fundamental ones, all other types of logic gate can be built using these 3, we’ll discuss the other gates and how to make them using these later.

 

A NOT gate, also known as an Inverter, takes an input and outputs the opposite value.

Input Output
0 1
1 0

An AND gate takes inputs, if they match a 1 is output, if they differ then the output is a 0.

Input A Input B Output
0 0 0
0 1 0
1 0 0
1 1 1

An OR gate takes  inputs, if any of them is a 1 then the output is a 1 otherwise it is 0.

Input A Input B Output
0 0 0
0 1 1
1 0 1
1 1 1

 

That’s all well and good but a single logic gate isn’t particularly exciting or useful, the magic starts when they’re combined.

Before we get to that we’ll go over the other types of gates and what they do:

  • NAND
  • NOR
  • XOR
  • XNOR

 

As you may have worked out by either the names or the symbols these are basically modified versions of the fundamental 3 we already discussed, a brief description and their truth tables are below:

A NAND gate is essentially the opposite of an AND gate, the output is 1 unless both inputs are 1.

Input A Input B Output
0 0 1
0 1 1
1 0 1
1 1 0

A NOR gate is the opposite of an OR gate, the output is only a 1 if both inputs are a 0.

Input A Input B Output
0 0 1
0 1 0
1 0 0
1 1 0

An XOR, also known as exclusive OR, outputs a 1 if either input is a 1 but not if both are a 1.

Input A Input B Output
0 0 0
0 1 1
1 0 1
1 1 0

An XNOR is the opposite of an XOR, it outputs a 0 if either input is a 1 but not if both are.

Input A Input B Output
0 0 1
0 1 0
1 0 0
1 1 1