DEV Community

Abhay Prajapati
Abhay Prajapati

Posted on

Basic Logic Not Math behind the boolean operator.

Gorege Boole tossed the concept of Boolean Algebra

and said one can represent any logical statement with AND, OR, NOT

Basic Logic is in their name

Starting with AND

assume AND as a 5-year-old child who demands telescope πŸ”­ and StarshipπŸš€, so if you provide him with both stuff he will be happy, and if anyone or both aren't there the child will start crying.

Similar with AND if it say I want value x > 3 & y < 5 then the condition will only satisfy if both stuff are true

Telescope πŸ”­ Starship πŸš€ Output Q
0 0 0
0 1 0
1 0 0
1 1 1

Moving towards OR

the same child here also, where now he demand Falcon 9 OR Saturn 5 as he wants to Mars. So, if you provide him Falcon 9 he will be happy as his Mission will be completed with Falcon 9, but show you aren't able to contact Elon to arrange Falcon 9 but you are able to contact NASA for Saturn 5 even then the 5 yr Child will be happy. Also, if you provided him with both Falcon 9 and Saturn 5 he will be happy as now he can talk to the crew too.

Similar, to OR, if it wants Falcon 9 || Saturn 5 if it gets Falcon 9 it will be satisfied even if it got Saturn 5 he will be satisfied, but it won't satisfy if both are False

Falcon 9πŸš€ Saturn 5 πŸͺπŸš€ Output Q
0 0 0
0 1 1
1 0 1
1 1 1

Now comes NOT

not is very simple to understand, it is used to negate the condition, so if just convert's the value of the condition, from true to false and false to true.
| Input A | Input B |
|:-------:|:-------:|
| 0 | 1 |
| 1 | 0 |

Now comes XOR, NAND, NOR above basics.

XOR

XORonly wants one true value to be true, example the child only wants SpaceX or Saturn 5 but not both, if you give both he will break the rocket in two pieces, so please with XOR you can only give him one of them.

Input A Input B Output Q
0 0 0
0 1 1
1 0 1
1 1 0

NOR

A situation where one except's nothing from anyone, the child is now grown up, now he doesn't need your help to build a complete rocket. If you don't give him anything he will be happy,

Input A Input B Output Q
0 0 1βœ…
0 1 0❌
1 0 0❌
1 1 0❌

NAND

Here the child doesn't want both things from you he only even if you don't give anything to him he will be happy, but if you give him both he will cry, but you can give one of any.

Input A Input B Output Q
0 0 1βœ…
0 1 1βœ…
1 0 1βœ…
1 1 0❌

credits to Isaac Computer Science

Repo: @Day5 Blog

ping πŸ€™πŸΎ me on Twitter @abhayprajapati

Top comments (0)