Enroll Course

100% Online Study
Web & Video Lectures
Earn Diploma Certificate
Access to Job Openings
Access to CV Builder



Online Certification Courses

How Logic Gates Work: OR, AND, XOR, NOR, NAND, XNOR, And NOT

How Logic Gates Work: OR, AND, XOR, NOR, NAND, XNOR, and NOT. 

How Logic Gates Work: OR, AND, XOR, NOR, NAND, XNOR, and NOT

A logic gate is an intriguing term, but what does it actually mean? This article will define a logic gate and describe how each of the logic gates (OR, AND, XOR, NOR, NAND, XNOR, and NOT) operates. 

 

What Is a Logic Gate?

To begin, it's critical to understand that logic gates come in a variety of shapes and sizes. Even in our private lives, we are constantly processing information through a variety of logic gates. While our minds are optimized for this, we frequently are unaware of the thought process in progress. Nonetheless, it occurs.

For instance, while taking an exam, one may be aware that failing to answer a question will result in a negative score for that question. If you considered this carefully and grasped the concept, you have just processed a NOT gate! In other words (pseudo code): if NOT {question answered} THEN negative consequences exist.

These logic gates serve as the foundation for a large portion of the world's code, as well as for electronics. While some logic gates are more common than others (for example, an AND or OR gate is more common than a NAND or NOR gate), all logic gates are used at some point to get a computer or electronic device to do exactly what is required of it—process data in a particular way.

We can construct workflows that resemble or follow human thought to some extent using multiple logic gates. Let us examine each one in greater detail.

 

OR

An OR logic gate is a very simple gate/construct that essentially states, “If my first input is true, or my second input is true, or both are true, then the outcome is true also.” Take note of the fact that we have two inputs and one output. This is not true for every logic gate. If you look at the header image, you'll notice that all logic gates have two inputs—with the exception of the NOT logic gate, which only has one. Each gate has a single output.

Alternatively, we can incorporate an OR logic gate into this flowchart:

0 + 0 => 0

0 + 1 => 1

1 + 0 => 1

1 + 1 => 1

In this case, 0 denotes false and 1 denotes true. As you can see, the only way for our output to be false (i.e. 0) is for both inputs to be false. In all other cases, our OR gate's output will be true.

Notably, if both inputs are true, the output will be true as well. This is a slight deviation from how a human would think about OR, as the term or is frequently associated with either one or the other.

 

AND

Similar to our OR logic gate, the AND logic gate processes two inputs and outputs one, but this time, we're looking for both inputs to be true in order for the outcome to be true. In other words, our logic proceeds as follows:

0 + 0 => 0

0 + 1 => 0

1 + 0 => 0

1 + 1 => 1

All other gates (with the exception of the NOT gate) are a little trickier to grasp, but stay tuned.

 

XOR

The XOR gate is also known as the EOR or EXOR gate. Exclusive OR is the correct terminology for an XOR gate. If you recall our previous example, we were somewhat surprised that true and true would still result in true, which is in contrast to human reasoning.

Welcom to XOR (exclusive OR), which resolves this issue in a manner consistent with conventional human reasoning. This logic gate operates as follows:

0 + 0 => 0

0 + 1 => 1

1 + 0 => 1

1 + 1 => 0

The input and output are identical to those of our OR gate, but this time the input must truly be exclusive. If both inputs are true, the output will be false.

 

NOR

Do you recall our previous NOT example? We've flipped the script. It is similar to the NOR gate, which is essentially a NOT-OR gate with the same logic as the OR gate discussed previously.

In other words, anything that is not an OR-situation (i.e. true and false mixed or true and false alike to our OR gate example, even if it does not seem logical to humans) results in a true outcome, while everything else results in a false outcome.

This result in the NOR gate logic shown below:

0 + 0 => 1

0 + 1 => 0

1 + 0 => 0

1 + 1 => 0

With this knowledge in hand, we can examine the NAND gate:

 

NAND

 

As with NOR, NAND can be interpreted as NOT-AND, which implies that anything that is normally an AND must be false (i.e. NOT-AND). This results in the following:

0 + 0 => 1

0 + 1 => 1

1 + 0 => 1

1 + 1 => 0

As with the first three cases, there is no complete AND (which would be true and true). As a result, the conclusion is correct (1). For the final input, true and true, a full AND is present, and thus the result is false (due to the NOT component, the N in NAND).

 

XNOR

When the OR, NOR, and XOR gates are considered, the XNOR gate is a combination of them. Essentially, a gate that is Exclusive NOT-OR or Exclusive NOR. The following logic applies:

0 + 0 => 1

0 + 1 => 0

1 + 0 => 0

1 + 1 => 1

In other words, the inverse of the result of an XOR gate. Yes, it can become somewhat complicated to follow.

 

NOT

We previously introduced the NOT gate in a brief manner using our human equivalent example. The NOT gate effectively reverses the direction of any input it receives. If you supply true as an input, you will receive false as an output, and vice versa. Our logic table is straightforward:

1 => 0

0 => 1

This gate is frequently used in conjunction with others.

 

Logic Gates in Computer Code

A simple NOT gate is demonstrated in the following Bash code:

if [ ! true ]; then echo 'false'; else echo 'true'; fi

In this example, we are essentially saying: if not true, then echo false, otherwise echo true. Due to the use of a NOT gate, the output is true even when the input is false.

As you can see, when NOT gates are combined with AND or OR gates, code becomes quite confusing to read and develop. However, practice makes perfect, and experienced developers enjoy the complexity of complex gate conditional statements.

A logical OR gate is frequently denoted by the || idiom in many coding languages, whereas an AND logic gate is frequently denoted by the && idiom. Typically, a NOT gate is denoted by the! symbol.

 

Conclusion

We discussed the OR, AND, XOR, NOR, NAND, XNOR, and NOT logic gates in this article. Additionally, we discussed how logic gates simulate human thought and how they can be used to assist us in writing complex pieces of programming logic in a computer program. Additionally, we took a brief look at logic gates as they are used in computer code.

 

Courses and Certification

Basic Computer Skills Course and Certificate

Basics of Computer Science Course and Certificate

Basic Electronics Course and Certificate

Computer Fundamentals Course and Certificate

Computer Graphics Course and Certificate

Computer Logical Organization Course and Certificate

Computer Programming Course and Certificate

Information Technology Fundamentals Course and Certificate

Corporate Training for Business Growth and Schools