d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Care To Explain?
Add Reply New Topic New Poll
Member
Posts: 5,869
Joined: Feb 28 2009
Gold: Locked
Trader: Scammer
Warn: 30%
Oct 6 2016 09:12pm




having a hard time understanding and, or, and not
Member
Posts: 3,939
Joined: Feb 1 2013
Gold: 2,749.09
Warn: 20%
Oct 6 2016 10:43pm
it's like in english
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Oct 7 2016 02:20am
Boolean expressions are best viewed as truth tables:



For a result to be true for "and" Both inputs must be true (denoted as 1). Any other combination and the result is false (denoted as 0).

For a result to be true for "or" either input must be true, if both are false then the output is false.

"Not" simply inverses the result.

Taking the first equation on line 4 we have:

Code
(2 <= 2) and "Alpha" == "Bravo"


We then simplify this, is 2 less than or equal to 2? Yes, so that input for the "and" is true (denoted as 1). Next the other half, is "Alpha" equal to "Bravo"? No, so that input is false (denoted as 0).

Now using the truth table for the "and" function we input a truth and a false (1 and 0) and in turn we get a result of 0 (false).

Now if you wanted to be cheeky you could do this for #7:

Code
(2 <= 2) and !("Alpha" == "Bravo")


Using the "not" operator on the alpha bravo comparison (which is false or 0) gives us back a 1 (true) from the "not" function. Finishing the equation we now have 1 and 1, which the result is 1 (true).

Similar cheekyness can be used for the or gates as well. Basically you don't need to change variables around and just change the operator functions. Just make sure they equate to the results you were expecting.

This post was edited by AbDuCt on Oct 7 2016 02:24am
Member
Posts: 5,869
Joined: Feb 28 2009
Gold: Locked
Trader: Scammer
Warn: 30%
Oct 7 2016 12:46pm
Quote (AbDuCt @ Oct 7 2016 03:20am)
.


Bravo man, thank you! :hug:

This post was edited by eazyBEEZY on Oct 7 2016 12:46pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 9 2016 07:24pm
Quote (AbDuCt @ Oct 7 2016 03:20am)
Boolean expressions are best viewed as truth tables:

http://science.slc.edu/~jmarshall/courses/2003/spring/cs10/lectures/week12/TruthTables.gif

For a result to be true for "and" Both inputs must be true (denoted as 1). Any other combination and the result is false (denoted as 0).

For a result to be true for "or" either input must be true, if both are false then the output is false.

"Not" simply inverses the result.

Taking the first equation on line 4 we have:

Code
(2 <= 2) and "Alpha" == "Bravo"


We then simplify this, is 2 less than or equal to 2? Yes, so that input for the "and" is true (denoted as 1). Next the other half, is "Alpha" equal to "Bravo"? No, so that input is false (denoted as 0).

Now using the truth table for the "and" function we input a truth and a false (1 and 0) and in turn we get a result of 0 (false).

Now if you wanted to be cheeky you could do this for #7:

Code
(2 <= 2) and !("Alpha" == "Bravo")


Using the "not" operator on the alpha bravo comparison (which is false or 0) gives us back a 1 (true) from the "not" function. Finishing the equation we now have 1 and 1, which the result is 1 (true).

Similar cheekyness can be used for the or gates as well. Basically you don't need to change variables around and just change the operator functions. Just make sure they equate to the results you were expecting.


Hilariously enough, why people tend to slip between CS, CE, EE, and Math.

They are all fun and typically involve some logic along the way!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll