Header graphics: Explain that stuff
Custom Search
Sponsored links

You are here: Home page > A-Z index > Logic gates

A wooden gate in winter snow

Logic gates

Last updated: April 13, 2008.

You probably know that calculators and computers store decimal (0-9) numbers as long strings of zeros and ones in a form called binary code. Each number is stored using microscopic electronic switches called transistors. It's easy to store binary numbers simply by switching transistors on and off. Switching on a transistor stores a number one; switching it off stores a zero. So storing numbers is easy. But how can you add, subtract, multiply, and divide using nothing but electric currents? Calculators and computers do this using clever electronic circuits called logic gates. Let's take a closer look at what they are and how they work.

Photo: A gate can keep you out or let you into a field. In the same way, a microscopic logic gate is a barrier in an electronic circuit that can let electricity through or stop it flowing altogether. Put lots of logic gates together and you make a machine that's capable of basic mathematical "reasoning".

Logic gates: circuits that compare

A logic gate might sound horribly complex, but it's simply an electric circuit with two inputs and an output. It receives two incoming electric currents, compares them, and sends on a new, outgoing electric current depending on what it finds. A logic gate is a bit like a doorman or bouncer who is allowed to let people into a nightclub only if they pass certain tests. There are quite a few different types of logic gate, the most common of which are called AND, OR, NOT, XOR (Exclusive Or), NAND (NOT AND), and NOR (NOT OR). Let's look at the three simpler ones, AND, OR, and NOT:

AND

Suppose you go to a nightclub where the doorman's job is to enforce a simple rule: "Everyone in your group must wear a tie to come in". You go along with a friend one night. If you're both wearing ties, you'll get in. If only one of you is wearing a tie, or if neither of you is, neither of you will get in. An AND logic gate works the same way with two electrical inputs. If both inputs are switched on (that is, carry a number 1), the output will be 1 as well. Otherwise the output will be 0. In electronics, we can represent an AND gate with this little symbol. Three ways in which the gate can work are shown below.

AND logic gate

OR

You're not wearing a tie, so you go to another club further down the street. Here, the person on the door is enforcing a different rule: "A group of people can come in if any one of them is a member". If either you or your friend is a member, or if you both are members, you can both come in. If neither of you is a member, you're both left out in the cold. An OR logic gate works this way with two electrical inputs. If either input is switched on (that is, carries a number 1), the output will be 1 as well. Otherwise the output will be 0. In electronics, we represent an OR gate with a different symbol. Three ways in which it can work are shown beneath:

OR logic gate

NOT

So far, you've failed to get into either of the clubs. But there's one last hope: you know a friend is having a party a few streets away. The only trouble is, there's a really argumentative and contrary person on the door. He talks to each person in turn as they approach him. If you're nice and polite, he shouts abuse at you and turns you away. But if you're rude to him, he likes that for some reason and lets you in. In other words, he does exactly the opposite of what you'd expect! In electronics, there's a logic gate that works in the same, contrary way and it's called a NOT gate or invertor. Unlike AND and OR gates, it has only one input and one output. The output is exactly the opposite of the input, so if the input is a 0, the output is a 1 and vice versa. Here's how we represent a NOT in electronics. Two ways it can work are shown beneath.

NOT logic gate

The other three common logic gates are variations on these three. XOR (Exclusive OR) is like an OR, but it switches off if both the inputs are switched on. NAND is just like AND, only the end result is swapped over (so where AND produces an output of 1, NAND produces an output of 0). NOR is like OR with the end result swapped over in the same way.

Calculators can do all the things they need to do using different combinations of logic gates. It's logic gates that control how the display works in a calculator and more logic gates that figure out the results of calculations. Let's take a closer look...

Controlling a calculator display with logic gates

Please note: You might want to take a look at our article on calculators before you read on.

Each segment of the display is switched on and off by a series of logic gates that are connected together. Consider just the bottom lower right segment (shown in the picture, right, in blue). We need to turn this segment on if we're showing the numbers 0 (binary 00), 1 (01), 3 (11), 4 (100), 5 (101), 6 (110), 7 (111), 8 (1000), and 9 (1001)—but not if we're showing the number 2 (10). We can make the segment switch on and off correctly for the numbers 1-15 by rigging up three OR gates and one NOT gate like this.

How logic gates control the display segments

If we feed the patterns of binary numbers into the four inputs on the left, the segment will turn on and off correctly for each one. For example, feed in the number 7 as the four inputs 0111 and the gates will trigger like this, correctly switching on the segment:

How logic gates control the display segments

The other six segments of each digit are controlled by other combinations of logic gates.

Calculating with logic gates

It's possible to do any calculation you can think of by combining a different pattern of logic gates. The gates compare and combine two series of binary numbers, corresponding to the decimal numbers in your calculation, and produce a new series of binary numbers equal to the result. Addition is carried out by circuits called half-adders and full adders (which can carry on the results of a previous addition); subtractors work in a very similar way; multipliers use a collection of AND gates to multiply two numbers with a series of additions.

Sponsored links

Text copyright © Chris Woodford 2007. All rights reserved.

All unattributed images (those created by Explainthatstuff.com) are licensed under a Creative Commons License.
Please kindly take a look at our copyright notes before using material from this website.
Product photos are included for illustrative purposes only.
They do not represent any endorsement by us of the products shown
or any endorsement by the product manufacturers of this website or anything we say in the text.

Please help our chosen good cause! WaterAid brings clean water and sanitation to people in 17 developing countries Water Aid logo

Share this page

Help other people find this page by bookmarking it with:

Delicious   Digg  reddit   Facebook   StumbleUpon  Google   Twitter   Email it to a friend

Link to this page

If you'd like to link to this page, thank you! Here's some code you can cut and paste:

Can't find what you want? Search the Web here!

Custom Search