Post: Basic Engineering: Logic Gates AND, OR, NOT
10-06-2015, 02:00 AM #1
Specter
Pro Memer
(adsbygoogle = window.adsbygoogle || []).push({}); Introduction: I could have posted this in the learning center but I thought it better suited to computer programming, as even though it's the fundamental hardware of a computer, you'll see many types of these in software and programming as well. I'm thinking of doing a little mini-series of threads on these because they're kind of interesting and cool to know. What if I told you that you could store 1 bit of data with nothing but a few wires, a 9V battery and a 7476 IC? Not incredibly practical, but it's kind of cool to think about. In this first part I'll only cover some basic gates, I won't go as far into flip-flops and timers and adders, soon though :p



Binary and Hex: A computer only understands two things, if something is on, or if it's off (1 or 0). There are no other states. A computer doesn't understand 2, or 3, or even A. A computer doesn't understand "Hello" either, it understands 0110100001100101011011000110110001101111. It doesn't understand 0x804B19 either, hex (or base 16), that is just for human readability. Similarly to how in decimal (base 10) we have our 1's, 10's, 100's, 1000's, 10 000's, etc. columns, in binary we have our 1's, 2's, 4's, 8's, 16's, 32's, 64's, 128's, etc. You just have a sum and a carry, this is why processors and memory (and storage by extension) is stored in terms of 32 or 64 bit, and 1024mb in 1gb. I won't go into the full system but what's important to understand is 0 is off, 1 is on, or 0 is LOW and 1 is HIGH.



The AND Gate: An AND gate is the [s]most[/s] fundamental gate (Beach and Joren pointed out the NAND is actually the most fundamental, but nonetheless the AND gate is still important), you can make practically anything with any number of NAND gates. An AND gate typically has two inputs, A and B, but it can have more (typically not less). As the name suggests, f (or the output) will only evaluate HIGH (or a 1) if all of it's conditions (inputs) are true. We list all possible input combinations and its given output in a truth table. Here is an example:

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]B[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[td]0[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]1[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[/table]

Originally posted by another user
A good example I like to use for this is an ATM. Your card, your pin, and your balance has to check out, that is the only way you will successfully withdraw any money. If any of these conditions are false, such as you don't have a sufficient balance or your pin is incorrect, you're walking home empty handed.


The notation for AND in a boolean (true/false) equation is a dot (like multiply), so the equation for a two input AND gate assuming A, B are inputs and f is the output is f = A • B How would we draw this in a logic diagram? The conventional symbol for an AND gate is a D shape with two leads going in for the inputs, and one lead going out for the output.
You must login or register to view this content.

Originally posted by another user
Where is this found in programming?
In any common programming language, you'll see this in logic control statements, such as if(). An example would be if(a && accessLvl >= 2), both a as well as accessLvl >= 2 have to evaluate true for the block to be executed.




The OR Gate: The OR gate is also a fundamental gate, and as the name suggests, the output will be HIGH (or 1) if either or all conditions are true. Below is the truth table;

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]B[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[/table]

Originally posted by another user
A good example of an OR gate is a fire alarm. Typically in public buildings, the fire alarm will sound if either the alarm is pulled, OR if smoke is detected. Either one or the other has to be true for the alarm to sound, not both, however if both are pulled at the same time there's no difference and the alarm will sound just the same.


The notation for OR in a boolean (true/false) equation is a plus (+), so the equation for a two input OR gate assuming A, B are inputs and f is the output is f = A + B How would we draw this in a logic diagram? The conventional symbol for an AND gate is a D shape with two leads going in for the inputs, and one lead going out for the output.
You must login or register to view this content.

Originally posted by another user
Where is this found in programming?
Again, you'll see this in logic control statements, such as if(). An example would be if(name == "bob" || name == "jim"), the block will execute if the name variable contains either the string of "bob" or "jim".




The NOT Gate: The NOT gate is called a hex inverter, all it does is invert it's input, so it only has one input and one output. This gate is combined with other gates to form more complex gates like NAND (NOT + AND) or NOR (NOT + OR). The truth table for an inverter is as follows;

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[/tr]
[/table]

To notate that you're inverting an expression you simply draw a line above your question, showing that it's been inverted. An example of this is Q in a J-K Flip-Flop, you'll have Q and Q NOT.
You must login or register to view this content.

Originally posted by another user
Where is this found in programming?
Anywhere anything is inverted, for example "execute if socket is false, throw error, die", this is used in PHP often, and you'll see it something like if(!socket).




Conclusion: This was just a small thread on the basic three gates, however it's necessary if you want to understand the rest of my mini-series as it builds off of these gates. If you have anything that I should add, please do suggest it and I'll consider adding it in Awesome face
Last edited by Specter ; 12-08-2015 at 07:22 PM.

The following 4 users say thank you to Specter for this useful post:

Bad Luck Brian, Helping-Hand, Jim Halpert, Trefad
10-06-2015, 05:02 AM #2
Trefad
I defeated!
Nice, thanks!
Last edited by Trefad ; 10-06-2015 at 05:58 AM.
10-14-2015, 07:36 AM #3
is the boolean algebra for an and gate an actual dot product operator? and I see additive and multiplicative operations but is exponentiation so explicit in logic?
10-16-2015, 05:52 PM #4
AppleTechKid
Trustworthy: Level 1
Originally posted by Specter View Post
Introduction: I could have posted this in the learning center but I thought it better suited to computer programming, as even though it's the fundamental hardware of a computer, you'll see many types of these in software and programming as well. I'm thinking of doing a little mini-series of threads on these because they're kind of interesting and cool to know. What if I told you that you could store 1 bit of data with nothing but a few wires, a 9V battery and a 7476 IC? Not incredibly practical, but it's kind of cool to think about. In this first part I'll only cover some basic gates, I won't go as far into flip-flops and timers and adders, soon though :p



Binary and Hex: A computer only understands two things, if something is on, or if it's off (1 or 0). There are no other states. A computer doesn't understand 2, or 3, or even A. A computer doesn't understand "Hello" either, it understands 0110100001100101011011000110110001101111. It doesn't understand 0x804B19 either, hex (or base 16), that is just for human readability. Similarly to how in decimal (base 10) we have our 1's, 10's, 100's, 1000's, 10 000's, etc. columns, in binary we have our 1's, 2's, 4's, 8's, 16's, 32's, 64's, 128's, etc. You just have a sum and a carry, this is why processors and memory (and storage by extension) is stored in terms of 32 or 64 bit, and 1024mb in 1gb. I won't go into the full system but what's important to understand is 0 is off, 1 is on, or 0 is LOW and 1 is HIGH.



The AND Gate: An AND gate is the most fundamental gate, you can make practically anything with any number of AND gates. An AND gate typically has two inputs, A and B, but it can have more (typically not less). As the name suggests, f (or the output) will only evaluate HIGH (or a 1) if all of it's conditions (inputs) are true. We list all possible input combinations and its given output in a truth table. Here is an example:

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]B[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[td]0[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]1[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[/table]



The notation for AND in a boolean (true/false) equation is a dot (like multiply), so the equation for a two input AND gate assuming A, B are inputs and f is the output is f = A • B How would we draw this in a logic diagram? The conventional symbol for an AND gate is a D shape with two leads going in for the inputs, and one lead going out for the output.
You must login or register to view this content.





The OR Gate: The OR gate is also a fundamental gate, and as the name suggests, the output will be HIGH (or 1) if either or all conditions are true. Below is the truth table;

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]B[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[/table]



The notation for OR in a boolean (true/false) equation is a plus (+), so the equation for a two input OR gate assuming A, B are inputs and f is the output is f = A + B How would we draw this in a logic diagram? The conventional symbol for an AND gate is a D shape with two leads going in for the inputs, and one lead going out for the output.
You must login or register to view this content.





The NOT Gate: The NOT gate is called a hex inverter, all it does is invert it's input, so it only has one input and one output. This gate is combined with other gates to form more complex gates like NAND (NOT + AND) or NOR (NOT + OR). The truth table for an inverter is as follows;

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[/tr]
[/table]

To notate that you're inverting an expression you simply draw a line above your question, showing that it's been inverted. An example of this is Q in a J-K Flip-Flop, you'll have Q and Q NOT.
You must login or register to view this content.





Conclusion: This was just a small thread on the basic three gates, however it's necessary if you want to understand the rest of my mini-series as it builds off of these gates. If you have anything that I should add, please do suggest it and I'll consider adding it in Awesome face


I'm currently in my second year of University studying Electronic Engineering. This info is a great place to start! Nice thread man Smile
12-08-2015, 02:13 PM #5
Default Avatar
Bch
Guest
Originally posted by Spec
Introduction: I could have posted this in the learning center but I thought it better suited to computer programming, as even though it's the fundamental hardware of a computer, you'll see many types of these in software and programming as well. I'm thinking of doing a little mini-series of threads on these because they're kind of interesting and cool to know. What if I told you that you could store 1 bit of data with nothing but a few wires, a 9V battery and a 7476 IC? Not incredibly practical, but it's kind of cool to think about. In this first part I'll only cover some basic gates, I won't go as far into flip-flops and timers and adders, soon though :p



Binary and Hex: A computer only understands two things, if something is on, or if it's off (1 or 0). There are no other states. A computer doesn't understand 2, or 3, or even A. A computer doesn't understand "Hello" either, it understands 0110100001100101011011000110110001101111. It doesn't understand 0x804B19 either, hex (or base 16), that is just for human readability. Similarly to how in decimal (base 10) we have our 1's, 10's, 100's, 1000's, 10 000's, etc. columns, in binary we have our 1's, 2's, 4's, 8's, 16's, 32's, 64's, 128's, etc. You just have a sum and a carry, this is why processors and memory (and storage by extension) is stored in terms of 32 or 64 bit, and 1024mb in 1gb. I won't go into the full system but what's important to understand is 0 is off, 1 is on, or 0 is LOW and 1 is HIGH.



The AND Gate: An AND gate is the most fundamental gate, you can make practically anything with any number of AND gates. An AND gate typically has two inputs, A and B, but it can have more (typically not less). As the name suggests, f (or the output) will only evaluate HIGH (or a 1) if all of it's conditions (inputs) are true. We list all possible input combinations and its given output in a truth table. Here is an example:

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]B[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[td]0[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]1[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[/table]



The notation for AND in a boolean (true/false) equation is a dot (like multiply), so the equation for a two input AND gate assuming A, B are inputs and f is the output is f = A • B How would we draw this in a logic diagram? The conventional symbol for an AND gate is a D shape with two leads going in for the inputs, and one lead going out for the output.
You must login or register to view this content.





The OR Gate: The OR gate is also a fundamental gate, and as the name suggests, the output will be HIGH (or 1) if either or all conditions are true. Below is the truth table;

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]B[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]0[/td]
[td]0[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]1[/td]
[td]1[/td]
[/tr]
[/table]



The notation for OR in a boolean (true/false) equation is a plus (+), so the equation for a two input OR gate assuming A, B are inputs and f is the output is f = A + B How would we draw this in a logic diagram? The conventional symbol for an AND gate is a D shape with two leads going in for the inputs, and one lead going out for the output.
You must login or register to view this content.





The NOT Gate: The NOT gate is called a hex inverter, all it does is invert it's input, so it only has one input and one output. This gate is combined with other gates to form more complex gates like NAND (NOT + AND) or NOR (NOT + OR). The truth table for an inverter is as follows;

[table=width: 500, class: outer_border, align: left]
[tr]
[td]A[/td]
[td]f[/td]
[/tr]
[tr]
[td]0[/td]
[td]1[/td]
[/tr]
[tr]
[td]1[/td]
[td]0[/td]
[/tr]
[/table]

To notate that you're inverting an expression you simply draw a line above your question, showing that it's been inverted. An example of this is Q in a J-K Flip-Flop, you'll have Q and Q NOT.
You must login or register to view this content.





Conclusion: This was just a small thread on the basic three gates, however it's necessary if you want to understand the rest of my mini-series as it builds off of these gates. If you have anything that I should add, please do suggest it and I'll consider adding it in Awesome face


Correct me if im wrong, but i'm sure it's NAND or NOR gates which you can create any other game from, not AND. It's pretty cool how you can use logic gates in minecraft, i once made a 4 bit binary adder in minecraft :p you can also create flip flops in minecraft too

The following user thanked Bch for this useful post:

Specter
12-08-2015, 05:43 PM #6
Originally posted by Beach View Post
Correct me if im wrong, but i'm sure it's NAND or NOR gates which you can create any other game from, not AND. It's pretty cool how you can use logic gates in minecraft, i once made a 4 bit binary adder in minecraft :p you can also create flip flops in minecraft too


Correct, it's NAND.
Like the set of AND, OR, NOT gates, the singleton NAND gate set is functionally complete.
This means that any algebraic expression or truth table can be implemented by using only NAND gates.

EDIT:
If anyone is interested, this is how it's done (using Logisim):


NAND itself:

You must login or register to view this content.


AND :

You must login or register to view this content.


OR:

You must login or register to view this content.


NOT:

You must login or register to view this content.

Last edited by Joren ; 12-08-2015 at 05:50 PM.

The following 2 users say thank you to Joren for this useful post:

EncepT, Specter
12-08-2015, 07:20 PM #7
Specter
Pro Memer
Originally posted by Beach View Post
Correct me if im wrong, but i'm sure it's NAND or NOR gates which you can create any other game from, not AND. It's pretty cool how you can use logic gates in minecraft, i once made a 4 bit binary adder in minecraft :p you can also create flip flops in minecraft too


Yes this is correct my apologies, thanks for pointing this out.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo