Friday, May 27, 2022

# LIVE Shop Talk 34: Understanding Difference Between Binary and Boolean, or Logic Operators

Hello guys this is paul mcquarter with toptechboy.com and we are here today live live live with let's talk episode number 34. i'm going to need you guys to pour yourself a nice cup of hot coffee yes it has turned a little bit cool here in west texas so for the duration we will be enjoying hot .

Coffee and then in the spring we will return to our traditional ice coffee let's see do we have any guys out there okay we've got some people tuning in the green diamond rob kevin super jet shuttle pod one sudharshan uh inver uh we've got quite a crowd joining us here so that's .

Really good because i got a great lesson for you today and i think it's something that is really important and i think it's something that a lot of people are confused about and really there's a lot of confusion out there on this topic but the good news is there's a really really simple .

Explanation and i want to help you understand it and so what i want to talk about today is i want to talk about the difference between binary and boolean okay they're both very very similar but they're really completely different and so it's very easy to get the concepts of binary and .

Boolean and logic operators confused and so that's what i'm going to be talking to you guys about today hey we've got uh ken sunali dancing star pro gamer tennis vp uh varantija subhan muraban melvin soublon zanted morgan hey we got a great crowd showing up glad to have you guys here .

Sorry i'm not pronouncing your name right but i do want to give you a shout out so what are we going to talk about today we are going to talk about boolean and binary and the difference between those two so kind of by way of introduction there are a lot of layers between where .

You're operating which is like at the arduino ide or at the python level there's a lot of layers between that down to the bare silicon the raw silicon and what i think most people are kind of familiar with is is that everything in a computer .

Works with zeros and ones that if you peel the onion back far enough down at the very base level of an integrated circuit or a microprocessor you have transistors a transistor is a switch a switch the transistor switch is either on .

Or it's off if that switch is on it represents a one if that switch is off it represents a zero and so everything in a microprocessor everything in digital electronics is just zeros and ones now you kind of know that and the physical .

Entity that makes the zeros and ones work are transistors and on a modern integrated circuit this is a full silicon wafer on a modern integrated circuit you can have billions that's billions with a b of transistors and you have all these little transistors which are .

All of these little on off switches and then we sort of think of those in terms of zeros and ones so as a normal kind of guy operating at the program level operating at the arduino level you you sort of know that everything is based on zeros and ones okay but the thing that gets confusing .

Is there's really two completely different sort of sets of zeros and ones and they really behave completely differently each one is represented by a transistor that's on or off but the concepts between them are completely different so i want to kind of break that down .

For you today and what i also see is some of you guys might not really you might understand everything comes down to zeros and ones but you might not really understand how binary works and so that's kind of what i want to do today is i want to go in and sort of talk to you .

About how the zeros and ones work all right so let's see is this going good okay this looks like it is still going so let me come over here and let me switch to a different view let me see this looks like a good view okay and so we will come over here and i .

Will get out of your way and uh what i am going to be talking to you about let me see here i am uh i need just a second here to get this turned back to the right shot hopefully you guys are still seeing me okay there that looks good all right had a little glitch in the studio there but .

We'll get back we'll get right back right back to it okay so the first thing i want to do before explaining the difference between boolean and binary what i want to do is kind of give you a recap of binary really quickly okay some of you guys might already know this .

But i'm not sure everyone knows it so we want to start with what we understand okay what we understand is decimal okay that's base 10 and why do we call it base 10 because you have 10 different characters or 10 different digits that you can work with okay video is not come in okay you guys let me know hey philippe wow we .

Got a super chat okay we got a super chat there felipe you are always most generous and i want to thank you because i'm you're keeping me in coffee philippe i really uh i really appreciate that okay so i want to talk to you about binary and to explain binary i want you to .

First start thinking about decimal okay or base 10 why do we call it base 10 because you have 10 different digits to work with so if we were going to count in decimal where do we start well we need to start with a 0 because that's really the first character .

And then count with me 0 1 2 3 4 5 6 7 8 9. now let's stop okay what you have to see is even though we've just counted to nine how many of our digits have we used up somebody tell me i counted from zero .

To nine how many of my digits have i used up okay i've used up all 10 because when you start with 0 and go to 9 you've really used up all 10 digits does that make sure does that uh does that make sense yeah tv tom said 10. .

All right so now i want you to think very carefully because to understand binary what i want you to see is what is the problem that we have when we get to nine we've used up all of our characters so we have to what start over and so when i ask you what is 9 plus 1 don't say 10 .

Okay if you want to understand binary when i say what is 9 plus 1 don't say 10 what is nine plus one well i have to go back to where i started so nine plus one is zero carry the one okay nine plus one is zero carry the 1. so if you understand that .

And then it looks like your old friend the 10 but don't think of it as 10 think of it as 0 carry the 1. now let's say if we just had 4 characters instead of doing base 10 we're going to do base four how would we do that we would start with .

Zero and then we go one two three okay and look i've used up all four of my carrier all four of my characters so what is in base four i'll label this up here base four i go zero one two three and base four what is three plus one i'm going to give you a .

Second here to put it in what is three plus one somebody tell me what is three plus one yes tv toms you got it it's zero it's zero carry the one okay and so one zero in base four would be the same as the number four okay because we got to three .

We add one to it and then we get to four so very good tom she said zero carry the one now if i all i have to represent digits is a switch that is on or off if i just have a switch that is on or off how many different characters do i have .

If it's zero or one right i have two characters it's a zero or a one an on or on off okay so let's count in binary we're gonna start with zero right and then we're gonna go to one okay so i have zero and one now i need to add one more okay i go zero one i need to .

Add one more in binary i'll write that up here in binary in binary what is one plus one somebody please tell me what is one plus one in binary and answer it right it is uh yeah carlo not quite i don't want you to say one zero times you've got it it is .

Zero carry the 1. okay and that does come out to 1 0 but i want you to think of it no no no god's not 1 0. you got to think of it as 0 carry the 1. because if you think of it as 0 carry the 1 we can do the whole of binary and everything will work because .

If we get in the middle of a problem you can't make 1 plus 1 equal 1 0 you got to make it 0 carry the 1. so believe me if you will just think of this in terms of zero carry the one you can do the whole thing okay so let me do a uh let me let me do let's just do four bits and let's go .

Through kind of the whole counting so we're going to start with 0 0 0 0 and if i add 1 to it that's easy i'm going to get 0 0 0 1. all right now i need to add to that what's 1 plus one well it is zero carry the one and then zero zero now zero plus .

One is one we still have this one zero zero now okay now i've got to add 1 to this if i add 1 to this what do i get 1 plus 1 is what 1 plus 1 is what somebody tell me i know there's a little delay here but somebody tell me one plus one is what .

Nobody is answering me uh z zero carry the one supergiant you're getting it it's zero carry the 1. now i've got the carried one and this one so now i've got 1 plus 1 again that's 0 carry the 1 and then a 0. now this is easy add 1 to it it's 1 0 .

One zero now add a one and i get zero carry the one the one and the zero now i add a one that's easy one one one zero now i'm to add one and you guys have got to see you've got to do it yeah uh pratham zero carry the one subharshan zero carry the one tad zero carry the one .

Yeah so now i'm going to add one what is it 0 carry the 1. now i have 1 and 1 that's what 0 and carry the 1. 1 and 1 is what 0 carry the 1. then i'll have 1 0 0 1 1 1 0 1 0 1 0 1 1. now let's add 1 to it well i'm going .

To get 0 carry the 1 0 carry the 1 and a 1 then i'll get 1 1 0 1 that's easy 1 1 1 0 and then 1 1 1 1. okay now what are the decimal numbers well this is 0 1 2 3 4 5 6 .

7 8 9 10 11 12 13 14 15. now if i added one more i'm out of bits so i would go back to zero and that carry the one that carry would become an overflow i've overflowed my four bits if i wanted to go further i would have to add a .

Fifth bit or a fifth transistor does this make sense okay so i got to have you guys think in terms of zero carry the one okay now what i want you to see is is that you can do kind of like normal math what if i had .

0 0 1 1 and i added to it 0 1 0 1 i want to add those two numbers okay 1 plus 1 is what somebody tell me what 1 plus 1 is i'm going to wait for you i know there's a little delay here but i'm going to wait for you 1 plus 1 is what zero carry the one yes .

Zero carry the one now one plus one is zero carry the one one plus one is zero carry the one so zero 1 1 plus 0 1 0 1 is 1 0 0 0. now let's see where is this 0 0 1 1 well 0 0 1 1 is a 3 right so that is a 3 and what is 0 1 0 1 .

That is a 5 okay and we know that 3 plus 5 is 8 well let's look up 8 here eight is one zero zero zero okay do you guys see how that works do you see how in decimal it's three plus five is eight in binary it's zero zero one one zero 0 1 becomes a 1 0 0 0. so .

You can do real math and binary okay let's show off a little bit and even show that you can do multiplication so let's go 0 1 0 1 times 0 0 1 0 okay and i want to multiply well i do long multiplication so what i take this 0 times all of those digits well 0 times one is zero .

Zero times zero is zero zero times one is zero zero times zero is zero now i come over to this place and i say one times this number one times 1 is 1 1 times 0 is 0 1 times 1 is 1 and 1 times 0 is 0 and then i do another one i do this 0 i'm going to do this one here .

And so then that's going to be 0 0 0 0 and then i've got to do this one here and that's going to be 0 0 0 0. this is just long multiplication right and what do i get i get a zero a one i'm adding these up now a zero and a one and then zeros so i have this times .

This is this okay so now let's check that out and see how that works all right let's check that out and let's see how it works 0 1 0 1 what is that that is a 5 okay that is a 5 and then 0 0 1 0 that is a 2 and then what is this 0 1 0 1 0 that is .

A 1 0 1 0 okay like that and that is 10. so do you see that 5 times 2 is 10 do you see how it works so i can do math by taking numbers turning them into binary and then doing all the old math whether you add subtract multiply or divide .

Now i'm not going to do long division for you but you could do long division just like we just did multiplication and it all works in binary just the same as it does in decimal if you sort of see how this uh how this pattern is going okay so that .

Is binary now what you have to see is with binary with binary okay what you have to see with binary is is that you're taking decimal numbers and you're turning them into base two numbers but they're still numbers also what you can see then is is that .

Anything you can turn to a number so you could have a certain number represent a a certain number represent b a certain number represents c and so therefore you can have text and you can have words represented by binary also colors like you could think red you .

Could have a red string from 0 to 255 that's an 8-bit number okay an 8-bit number so you could represent how strong red is with 8 switches or eight binary digits and then if you had red green blue in each one of those eight bits total of 24 bit .

You could represent any color that you wanted to so colors can be changed to binary numbers can be changed to binary words can be changed to binary even music can be changed to binary so anything that you want to do you can represent with binary numbers okay now this is the thing though there .

Is something really really really important in digital electronics and how the arduino works if you were really able to look under the hood and that is something that is called logic okay and logic also involves zeros and ones okay .

Logic also involves zeros and one but what we're going to do is it's no longer really binary it is logic okay and there is a math that goes along with logic and that math is called boolean boolean algebra okay boolean algebra is the math that .

Allows us to use logic but the thing to understand is while it is zeros and ones it is completely different from what we have just said okay so i want you guys to participate with me here to try to understand this all right so i want everyone to respond but don't respond until i finish the .

Question okay now you're gonna all answer my question with either a zero or a one if what i am saying is true for you then answer with a one if what i am saying is false for you then answer with a zero okay so everyone should answer and you should answer a zero .

Or a one but everyone can have a different answer because it depends on who you are okay if you so everyone's gonna answer okay if you are a male and over 65 enter one if you're not enter a zero so male and over 65 answer with a one otherwise a zero okay .

I've got some ones coming in zeros okay okay so we've got like three people that are a man and over 65 and then we have a whole bunch of zeros okay so we've got ones and zeros coming in but did you see it looks like that mainly we got zeros there okay it looks .

Like we got mainly zero i'll give you guys a chance to finish answering that question mainly zeros okay now i want you to answer this question okay i want you to answer this question and this question is going to be different i want you to type in a one if you are a man .

Or you are over 65 if you're a man or if you're over 65 enter a one otherwise a zero okay look now all of a sudden look now all of a sudden we're getting almost all ones okay so you see how it sounds like almost exactly the same .

Question but the difference was the difference between the word and and the word or in those two different questions it changes everything okay but what i want you to see is we're still talking about zeros and ones okay we're still talking about zeros and ones but we're not talking about .

Binary okay we're not talking about numbers we're talking about logic we're talking about true or false okay so uh let's see here guys i don't want any of this nonsense okay so you guys don't uh don't try to slow us down here all right let's just see .

If you are a female if you are a female and over 20 years old a one otherwise a zero if you're female and over 25 enter a one okay female over 25 enter a one otherwise a zero okay are you guys out there okay zero zero yeah we so it seems like we have .

Mainly men on this channel so we don't see anyone popping up i have not seen anyone popping up of being a female over 25. hey carlo all right wow hats off to you carlos so we did get one one in there okay good job okay so do you see the difference between and and or okay so i want to reduce this .

Down to like boolean logic here so you sort of understand how it works but what you need to see is and when you're writing equations and is like the multiplication sign and or is the plus sign even though this plus is not that boolean plus that we were doing before .

It's not that boolean plus that we were doing before it is this logical or and so let's think of this let's say that for each one of those i had how many inputs i had two inputs i had two inputs and i had one output okay and you guys gave me .

Your output right and so let's think about this all right and so the inputs could be that you were like let's say if i was asking about if you're a male over 65 well you're not a male and you're not over 65 and so then you turned in a zero okay and then you could say well are you .

A male and you are over 65 well it's still zero or you're uh like this it's still a zero or if you are a male and you're over 65 then you get a one okay but you only get a one if you're both a male and you're over 65 okay .

But that's different than an or or a plus here you're not a male you're not over 65 and you get a zero well here you are a male you're not over 65 but because it's or it's a one or you're not a male but you are over 65 that's a one and then here if you are both yeah it .

Still turns out to be a one and that's why when i asked the first question it was almost all zeros and when i asked the second question it was almost all ones and the difference was because it was the difference between the logical .

Operator and and the logical operator or okay and then what you can actually do is you can actually get circuit elements you can get logical elements that you can plug onto your little breadboard and you can build these functions in and these .

These are what the symbols are this is a and gate okay it has a little dot here it has one output and it has two inputs this is an and gate and then this is an or gate an or gate looks like this if i can draw it it has a little plus in there and then you have two .

Inputs and so like if i come in here and i have a one and a zero in an or gate i will get a one out on an and gate if i have a one and a zero i will get a zero out okay then to do different functions you can do different things and so let's just say i can write a math equation here but it .

Is not a binary math it is a boolean math okay so let me let me make a little a little math equation here i could say a times b okay plus c times d all right what would that circuit look like well it starts with an .

And gate okay and i'm going to put in input a and i'm going to put in input b and then i'm going to take that output and it is going to go into an or gate my drawing is not getting very good there let me get a little bit further out of your way a little bit further out of your way okay and then .

I also have to deal with this c times d all right so i come over here another and gate and i have c and d so this is my output i'll write that as output so the output of this circuit the output is equal to a times b plus .

C times d okay but this is the logical operator and this is the boolean and this is not binary multiplication and this is the boolean or it's not the binary add that i was doing before so do you see that this still is all zeros and ones and so .

Let's let's do let's do one here okay so let's say that i had a zero zero and a one one what would the output be well right here i would have a zero and right here i would have a 1 but a 0 ored with a 1 is going to give you a 1 output okay so you see this is still zeros and ones but it's it's boolean .

It's logical it's not binary and computers as you peel back the onions as you start looking down in those lower layers this is one of the things that you find you find these digital uh logic gates or these boolean functions okay .

Now before besides the and in the or there's nand there's no there's exclusive nor there's there's not there's exclusive or there's probably six or seven different ones but if you understand and and or you can understand all of the different ones .

Okay so how would you use something like this well let's say that i have three smoke alarms like let's say what's the problem if you just have one smoke alarm the problem if you have one smoke alarm is is that you could get false right you could get false uh you could .

Get false alarms what if it was broken or something and so what you'll want to do is like if you think of something like a smoke alarm what if you wanted to have redundancy okay and so let's say that instead of one smoke alarm let's say that i had .

Three smoke alarms all right now if i had three smoke alarms okay those are going to give me three outputs okay they're going to give me a 0 if all is okay and they're going to give me a 1 if there is a fire okay and then my output would be .

To sound an alarm okay so tell me how if i had three of these smoke detectors what would probably be the best way to get the most accurate signal assuming that at any given time you could have like one of these smoke detectors you know go out it might not be working .

Tell me what algorithm we would use for these three smoke detectors okay you're saying ands and ors but just tell me more conceptually how you would do it averaging all three is not uh averaging all three is not quite the way that we want to do it okay so like let's think of the various .

Possibilities okay so i have the inputs from the three smoke detectors so this is a smoke detector this is a smoke detector and this is a smoke detector well the first one could so this is smoke detector a this is smoke detector b and this is smoke detector .

C so this is a b c okay so this is what you have to say if you had them all saying there was no fire and this is your output this goes to the alarm if all three of them said that there was no fire what would .

You want the output to be what would you want the output to be a zero or a one if all three smoke detectors said there was no fire what would you want the output to be yeah it's a zero okay what if i had the first one said there's no fire the second one said there's no .

Fire and then the third one said there was a fire what would probably and these three are at the same spot right they're kind of like all at the same spot what would we do if two of them agreed that there was no fire and one of them was saying that there was a fire .

Yeah we would say no fire probably a false signal from that one okay what if we had zero one zero okay well probably still no fire right yeah false alarm okay how about zero do you see how now even though this is a logical function i'm sort of stepping through them like they're .

Binary so what if i had 0 1 1 well that would be a 1 okay what if i what would the next one be 1 zero zero well that would be a zero all right and then what if i had one zero one right that would be a one because two of them .

Think that there's a fire now i could go one one zero well that one we would say yeah i want i want to turn it on there and the default three said there was a fire certainly i would turn it on like that okay so do you see that .

Yeah okay so do you see how that works so now how would we build this how would we build this well what we would say is the output is going to be equal to what are going to be the one conditions this one this one .

This one or this one okay so the output is going to be what we would say is i gotta get a term for this this this or this so i want the output to be 1 if i have a prime not a times b times c so if a is zero .

A prime would be one if a is zero a prime would be one so this condition here is going to be taken care of with this a prime times b times c okay then or which is a plus a b prime c this one a b prime c and b prime just means the opposite of b .

Okay and now i got to do this one which is going to be plus a b c prime okay and i'm going to have to get out of your way here it looks like abc prime okay and then what is the last one i've got to get this one okay and that is simply a b c so if .

This is true or if this is true or if this is true or if this is true i want the output to be a one okay if any one of those four is true so what am i going to need up here at the circuit level well i'm going to need an or gate and that or gate needs to have four inputs okay so i'm going to come over .

Here and i'm going to make an or gate and you can get or gates with four inputs and so this is going to be one input and this is going to be another input and this is going to be another input and then this is going to be another input i wish i'd .

Drawn that better and then each one of these inputs needs to have what connected to it what does each one of these or gate inputs need to be connected to it class class somebody tell me what does each one of these need in here and gates yeah big boggy face thank you .

Yeah so what i'm going to need is an and gate here and an and gate here and an and gate and an and gate here okay and these need to be three input and gates okay and you can get those .

Like that all right so this would be a prime the opposite of a and then this would be a prime b c this would be a b prime c this would be a b c prime or this would be a b c okay .

I hope you can see that well okay how would you do a prime well you can just there's another gate that's just called a not gate okay and a not gate is like that and so the way you could do this is uh let's see let me see if i can erase this here the way you could actually build this so .

You can kind of see that you could actually go out and buy gates to do this you could come out and you could put your a through a not like that so then you would have a then this is a prime the opposite of a and then this would be a prime bc this would be .

A b prime c this would be a b c prime and this would be a b c is this making sense is this making sense i hope it is but what you've got to see is this is called boolean algebra boolean algebra .

And this is very different than binary algebra okay so let's look at something if i did let's have 0 0 1 zero and zero zero zero one and then i'm gonna do it two different ways you guys cannot see that let me come back up to the top i'm sorry for that .

Let me come to a new sheet okay so now i'm going to say i want 0 1 0 1 and 1 0 1 0 and i want to add those and i want to do a binary ad a binary ad okay that's not a good example that is not a good example .

Okay so my example for binary add is going to be 0 1 0 1 and 0 1 0 1 and i want you to binary add those and then what i want is a logic plus okay and here i'm going to have 0 1 0 1 0 1 0 1. okay now how would we do this well one plus one .

Is zero carry the one one plus one is zero carry the one that is how you would binary add but here we just go through and bitwise them one or one is a one zero or zero is a zero one or one is a one zero or zero is a zero so can you see that if if this was a and this was b and this was a .

And this was b if i said what is a plus b well it's going to be 1 0 1 0 if you're doing a binary add okay but a if that plus is the logical or it's going to be 0 1 0 1. this is the logical this or the logical or guys is this making sense to you .

I mean man when i went through electrical engineering i really got confused now i still get confused with this because i have to stop and i have to think are we doing boolean algebra are we doing binary algebra and the two of them are different okay felipe says that this .

Makes sense okay again felipe really appreciate your generosity you're always helping me out on these things and it's really appreciated so it's a it's a real encouragement to me when when you guys help me out like that okay so let's see if we can play around with .

This a little bit with the arduino okay i'm going to kind of kind of live dangerously and see if i can do a little coding here live let me see if i can get a little different view a little better view here you see i got my arduino out there and so i'm going to create a variable that i'm going to call .

A and it's going to be the integer a and i'm going to make it though i'm going to make it the boolean and i'll do 8-bit numbers here i'm going to make it the boolean the boolean function let's say 0 one zero one zero one that's one two three four five six seven .

Eight seven eight okay one two three four five six seven eight okay now i'm going to do the integer b and that is going to be uh yeah the integer b is going to be okay what does this b mean this is just clueing the arduino in that this number is binary .

So i'm putting in the binary number 0 1 0 1 0 1 0 1 and then i'm going to put in the binary 1 0 1 0 1 0 1 0. okay now let's just look and see if this will work and then i'm just going to make an ntc .

Okay so do you guys understand what i'm doing here i'm making a a binary number i'm making b a binary number and then c i can also make that binary when i print it out and so what i'm going to do is i'm going to do a let's just say that c is equal to a .

Plus b okay c is equal to a plus b and serial dot print l n c okay now i want it to print out in binary two so i go like binary like that and it'll print it out in binary it'll give the answer in binary okay so some got somebody tell me what is this going to print out .

A is the binary number 0 1 0 1 0 1 0 1 and b is 1 0 1 0 1 0 1 0. somebody tell me what that's going to print out 1 1 one one we got somebody so let's see let's try this let's see if we can download this okay and now let's open up the serial monitor .

And i didn't get anything what went wrong oh i didn't start my serial monitor were you guys screaming at me to turn on my serial num my serial monitor man serial dot begin 9 600 that scared me a little bit when that didn't work let's try this again .

Okay all right let's try this boom okay sb was right one one one one one okay now for this case let's say instead of doing this is the binary end that plus is the binary and how would i do the boolean and the boolean and is a single vertical bar .

That single vertical bar it's sort of like the it's shift and then the key that's usually above the enter key on your keyboard now what is this going to do this one's going to be what somebody tell me what this one's going to be yeah it's the pipe 6 .

Symbol tv tom sure right it's just a lot of people are not kind of really familiar with that symbol very much okay we we say people say that it's gonna be zero zero zero zero we got some people thinking that a or b is going to be zero zero zero zero man .

Let's try it okay i've seen a lot of people thinking it's going to be zero zero zero zero okay let's try it one one one one you guys are not paying attention come on now look the first digit here is one or zero one or zero is still a one yeah themis yes .

Subharshan yes subharshan you changed your answer no fair you guessed both of them okay subojit yes okay yes right because this or this this one will flip it a one this or this this will flip it a one you gotta remember i did an or okay you want me to do an .

And you want me to do an and you want me to do the times right the little times the way you do an and is a single ampersand like that okay tell me what a and b is going to be what is a and b okay trippy says i said the wrong thing okay maybe i said the wrong thing .

Okay i'm sorry if i did okay now with and i meant i meant to say or if i mess it up i'm sorry okay so that is going to be the and and what is that going to give us that is going to give us 0. now this is the one thing that's kind of uh annoying yes supergit yes .

Shuttle pod one all you guys that said all zeros yeah the the annoying thing is when you print in arduino it it doesn't print the leading zeros it doesn't print out all eight zeros you would have to write a little function to do that but it's printing 0 0 0 0 0 as a 0. now if we did like this .

It'll print it out okay so now tell me we're going to use the logical and the boolean and somebody tell me what this is going to print out tell me what that one is going to print out with an and yeah dan you got it and themis this time you've got to put those trailing zeros .

Because it will put those trailing zeros in there because it's kind of treating it like a binary number so let's take a look at this let's download this okay boom one zero zero zero so let's see why because the first digit one ended with a one is a one one ended .

With a zero is a zero zero ended with a one one ended with a zero zero ended with one you see all the rest of those are zeros okay so then we can just do different ones like let's come in and let's say let's say that we did an or again okay and let's go .

0 0 and then let's go one one and then let's go zero one zero one and then let's go one zero one zero one zero okay somebody tell me what this is going to give us all right one zero one one one one okay .

Let's try supoged i think you know what's going on here yeah one zero one one one one because i am using the or operator i'm using the or operator right 0 or 1 is a 1. 0 or 0 is a 0. and then always here we have one of these as a 1. okay so do you see how this is .

Working where all of a sudden we're not doing binary math but we're doing logical operators now i don't know i haven't tried this i shouldn't try this stuff on the fly but i wonder if it would know like a not a probably not but i'm just trying to think i wonder if i could not the a .

And let's see what we got there okay so not a would be a one i think this no this did not work i was trying to get a not here so that would have made that a one which would have made it a one and then this would have been a one so that not a did not work okay the not a did not work .

I was wondering if i could do a logical a logical operator on the binary number but it is not allowing me to do that i'll have to look up and see i'm sure that there would probably be a way to a way to do that okay so do you guys do you guys understand .

Now the difference that we are talking about between a logical or boolean function and a binary function okay now what you could do is you could see that you can kind of combine these two things as well so let's look at this let's say .

I wanted to add ah that that was a mistake let's see uh okay let's say that i wanted to add two numbers let's say i have a b and then c d and so i want to actually add two binary numbers well what could those numbers be it could be .

0 0 0 0 okay and then what would i want the output to be well i would want the output to be 0 0 0 0 okay if i had 0 1 0 1 well that over here is like 0 1 0 1 right that's 1 0 so this would be 0 0 1 0 and then .

I could have you see how i could go through here let me let me start this again and i hope i don't mess it up right but i have two numbers i could have the first two numbers are a b and the second two numbers are c d and i want to add those together and i want to add them in a binary add .

Okay so i could have 0 0 0 1 0 0 1 0 i could have 0 0 1 1 i could have 0 1 0 0 i could have 0 1 0 1 0 1 1 0 0 1 1 1 i could have 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 .

1 1 1 0 0 and then finally 1 1 1 1. okay so now you have to think of the output if i had a zero and let me just i think i can do it with uh three uh i'll go ahead and put four outputs so the outputs are here here .

Here and here okay so if i have 0 0 and i add 0 1 i'm going to get a 0 1 and these bits are of course empty and so this is like saying 1 plus 1 1 plus 0 is 0. now this is 2 plus zero and that would be zero zero one zero and then a zero plus a three would be zero zero one one it would be .

Three okay zero plus 1 is going to go back and be 1. so i have 0 0 0 1 and then a 1 plus a 1 is going to be 2 so it can be 0 0 1 0 okay and a 1 plus a 2 is going to be 3 so that's going to be 0 0 1 .

1. okay is this making sense a 1 1 a 3 plus a 1 is going to go and it's going to round over to 4 0 1 0 0 okay now this is a 2 plus a 0 and so that would be 2 0 0 1 0. okay and then here i have a 2 plus a 1 would be 3 so that would be 0 0 1 1 and then here 2 .

Plus 2 is going to be 4 so 0 1 0 0 and then i have 3 plus 1 is going to be 4 0 1 0 0 and then i'm going to have 3 plus 0 which is going to be 3 and then i'm going to have 2 plus or this is 3 plus 3 right is going to be 6. .

So that's going to be 0 1 1 0 like that now i might have made a mistake in there somewhere i hope i didn't three plus one is four i think i got that those right hey man indian avatar thanks for the super chat really appreciate it that's very nice really appreciate you guys that are helping out there .

Okay so now let's call this output i have a b c d let's call this output e f g h so now i could come over here and say e is just always equal to 0 right so there's nothing that flips that because i didn't get enough digits to really make that go anywhere but then what i could say is .

F f is going to be equal to what well a prime b c d it's a prime times b times c times d do you see that when is f 1 well right here okay so that's a prime b c d will flip okay .

Where else will it be flipped on this case so it would be plus a b prime c d prime a b prime and you guys cannot see that let me go back a b prime c d prime okay and then uh it's also going to be plus .

I've got to get this one which is a b prime c d and then i've got to get this one which is a prime b c d prime okay so do you see that i could actually make a binary adder using logic functions and what i've got to do is i've just got .

To have a circuit for to produce e i've got to have a circuit to produce f i've got to have a circuit to produce g and i've got to have a circuit to produce h but i could add two bit numbers building a logic circuit so you see with .

This one it would be one two three four and gates and a three input or gate and then you see let me come down here to f you see i could build this f digit i've got to build a g and an h as well and then i'm going to have four inputs and each one of those are going to go to .

An and gate and each one of those and gates is going to have four inputs okay and so you see that i could actually build something that does math with these logical operators we could go buy a thing of and gates and or gates and we could plug them together and then we .

Could do real math with them we can use boolean algebra to do real math okay let me look over there and see if anybody is even paying attention anymore does this uh does this make sense guys does this make sense you see this is why it's so confusing because boolean is logic and then binary is just sort of plain .

Old-fashioned math but then i can use boolean and create a circuit that wouldn't even involve the arduino that could just be and in or gates and then i could do real math i could add with them okay all right hopefully oh you guys can't see the circuit all right sorry i'll get out .

Of your way all right so do you see how i have an or gate and then i have the four and gates and then i could make this well that just gives me the output f only so i would also need i would also need a circuit for e for g and for h okay for each one of those i .

Would need a i would need a separate circuit okay all right it seems like you guys are kind of catching on to this all right now this is the whole trick okay and this is why this is so important you guys are saying well why would i even bother with this .

Just get an arduino and do whatever you want right like if you want to do the smoke detector thing just get an arduino and do whatever you want well this is what you guys have to see is is that you know in the game of electronics it's a game of pennies all right and if you're building an electronic .

Element and you're using an arduino that might cost twenty dollars or maybe if you got a cheap knockoff maybe ten dollars okay and somebody else can do that same function by buying 25 cents worth of logic gates you know ands and or gates then you can't compete because he's building for .

Pennies what you built for dollars and so we love the arduino because we can do whatever we want to with it but the thing is in real applications you got to get your costs down and so if you can do it with logic gates you can do it a lot cheaper than doing it with a microcontroller so .

You only want to use a microcontroller for things that are more expensive and so for things like a smart smoke detector you would be way better off doing it with a few pennies worth of logic gates than putting an arduino in there does that make sense and so that is why this is really important because .

In real applications you want to first try to solve your problems with logic gates and then only use something like a microcontroller when that is all that you can do okay the one final thing i'll talk about and i really don't have time to go into this today .

But uh but i if you're interested i can go in to it another day the thing is is that if you were really like if we just did this brute force i think we decided we really didn't need the e okay we really didn't need the e but if you were gonna do this brute force you would need .

One two three or gates and you would need four and you would need four times three you would need 12 and gates and you would need three or gates if you were going to do this simple two-bit adder okay if you were going to do this simple two-bit adder you would need 12 and gates and you would need three or .

Gates that's 15 gates okay the truth is you could go in and if you were really tricky you could simplify you could simplify or reduce you could reduce this and you could do the same function with fewer gates and there's things .

Called boolean algebra where you start factoring and you start combining and then you can simplify this down to a simpler solution why do you want a simpler solution because then it takes less gates and you can do it at a lower cost and so that's boolean .

Simplification boolean reduction and there's some tools out there like called car now maps and if you learn how to do a car no map you can map this problem out and then you can significantly reduce yeah k-maps okay k-maps you can significantly reduce .

The amount of gates that you need to do this and again it's all about doing a job for the cheapest amount possible and certainly you don't want to use a micro controller if you don't have to and then secondly the guy that can do it with the fewest logic gates is the guy .

That's gonna have a product that actually makes it because the product can be made at a lower cost okay guys we have gone a little bit over here and so i want to thank you for uh i want to thank you for your attention i hope that this wasn't just totally .

Boring for you uh to me it's just really interesting and i've always kind of wanted to go in and sort of go in and start working more with the digital logic like take the arduino out of the picture and just get some and gates and or gates and start building circuits that do things and start .

Start doing useful functions using uh these more what would you say these more uh primitive uh uh operators like ants and oars okay guys really appreciate your time today hopefully i didn't bore you i'll be looking for feedback if this is the type of stuff you're interested in because i .

Don't want to do this stuff if it's not what you're interested in but let me know if this uh if this is what you're interested in guys if you like this give me a thumbs up if you haven't subscribed subscribe to the channel and as always i want to really thank you guys for the help with the super chats and also you .

Guys are helping me out over at patreon i really appreciate it and it keeps this great content coming okay guys this is paul mcquarter with toptechboy.com i will talk to you guys later

RELATED ARTICLES