Logic Gates and Circuits

This concept introduces one of the ways computers actually works; in this case, logic gates. According to Wikipedia: “A logic gate performs a logical operation on one or more logic inputs and produces a single logic output. The logic normally performed is Boolean logic and is most commonly found in digital circuits. Logic gates are primarily implemented electronically using diodes or transistors, but can also be constructed using electromagnetic relays, fluidics, optics, molecules, or even mechanical elements.” So basically in this article, I will demonstrate how digital circuits will perform logical operations on two bits (on/off). The use of this shows how you can manipulate the flow of electricity to mimic the bit-wise operations you can do in programming, which is actually what it is.

First I will start with the AND gate. As you may know, AND returns a 1 or True value if the two given bits are both 1, else it will yield zero. Here are all the possible scenarios and their results of the AND operation with two bits:

0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1

Here is a circuit diagram that applies the AND logic to result in the output value of the light being on or off:

    Switch A   Switch B

.------/ ---------/ ------.
|                         |
=                         o Light
|                         |
*-------------------------*

You see, both switch A and B have to be on for the flow of electricity to continue, thus powering the light. If at least one of the switches is not on, then the whole thing will be off. Likewise with the AND logic both bits have to be on or set to the value of 1 in order for the whole result to equal 1.

The next one is the OR gate. This gate outputs 1 if at least one the bits have a value of 1. The table of truth for the OR gate:

0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1

A digital diagram using the OR logic works like this:

        .---/ ---.
        |        |
 .------+        +------.
 |      |        |      |
 =      *---/ ---*      o
 |                      |
 *----------------------*

In this diagram, the flow of electricity can go on if at least one of the switches is on; for if one switch is off, then the electricity flow can take the route where the switch is on and connecting to an alternate route. If both switches are on, then its even better since the flow can go in one or split to both directions and then join again at the end of the fork and continue the flow of powering the light.

The XOR gate outputs a 1 if either but no both of the values are 1, or in human terms, if both of the values are not the same:

0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0

It doesn’t seem possible to demonstrate it well enough with ascii art so I got a diagram of XOR from searching Google Images:

I bet you were wondering how the XOR gate would work. Well now you see that it only works if only one of the switches is on but not both, because both paths cross each other thus canceling each other out if both sides have the same value. One switch on and the other off to connect the crossing path; a 1 and 0, a positive and negative to keep electricity flowing.

In assembly language these common logic operations are used all the time by the machine. For me, I haven’t found any application for this yet except for understanding how the computer works better. You can look up other logic gates and understand them more, but for now this remains as a post under the Concepts section.

One thought on “Logic Gates and Circuits

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: