Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2025 | Replies: 5
![]() |
•
•
Join Date: Jul 2005
Location: massachusetts
Posts: 12
Reputation:
Rep Power: 4
Solved Threads: 0
Im reading about logical operators (yes noob here) and Im sort of confused as to what some of them actually mean.
Example: if b1 is true and b2 is false
!(b1 & b2) is true
b1 | b2 is true
b1 & b2 is false
b1 ^ b2 is true
i know that:
& is AND
| is OR
! is NOT
^ is XOR
But the question is what do the above comparisons (b1 ^ b2), or (!(b1 & b2)) actually mean, if translated into english what does that say? And what is the difference between XOR and OR. I think XOR is actually false if both boolean values are the same, but im not sure on that one.
Example: if b1 is true and b2 is false
!(b1 & b2) is true
b1 | b2 is true
b1 & b2 is false
b1 ^ b2 is true
i know that:
& is AND
| is OR
! is NOT
^ is XOR
But the question is what do the above comparisons (b1 ^ b2), or (!(b1 & b2)) actually mean, if translated into english what does that say? And what is the difference between XOR and OR. I think XOR is actually false if both boolean values are the same, but im not sure on that one.
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation:
Rep Power: 19
Solved Threads: 200
•
•
Join Date: Jul 2005
Posts: 56
Reputation:
Rep Power: 4
Solved Threads: 0
Jwenting is correct you need to read up on the topic but i can explain a little to help get you started.
I think the way i treat boolean logic is kind of like math. As you can see there are ( ) in the equations. And according to math they should be my first order of opperations.
Starting with !(b1 & b2) if B1 = true and B2 = false then...
(1) B1 & B2 = false because they aren't both true
(2) !(false) = true becase all '!' gives you is the opposite
Now B1 | B2 (need to memorize truth tables for these)
With the or | (or) operator, it is true if n e of the terms are true
so since B1 = true it does not matter what B2 is, the answer is always true.
B1 & B2,
And is only true if all terms are true. Since B2 is false the answer is false.
B1 ^ B2,
XOR is confusing for like the first 30 seconds, or until somebody explains it correctly. As i've stated already, OR is true if any of the terms are true so
(OR)
FALSE | TRUE = TRUE
TRUE | FALSE = TRUE
FALSE | FALSE = FALSE
XOR stands for exclusive OR. And is ONLY true "IF AND ONLY IF" 1 term in the series or equation is true.
(XOR)
TRUE ^ FALSE = TRUE
FALSE ^ TRUE = TRUE
FALSE ^ FALSE = FALSE
TRUE ^ TRUE = FALSE
(remember when you see XOR, say to yourself "IF AND ONLY IF")
Just for people who think they might do some ASM in their future. Some handy uses of xor are...
a XOR 0 = a
a XOR a = 0
I think the way i treat boolean logic is kind of like math. As you can see there are ( ) in the equations. And according to math they should be my first order of opperations.
Starting with !(b1 & b2) if B1 = true and B2 = false then...
(1) B1 & B2 = false because they aren't both true
(2) !(false) = true becase all '!' gives you is the opposite
Now B1 | B2 (need to memorize truth tables for these)
With the or | (or) operator, it is true if n e of the terms are true
so since B1 = true it does not matter what B2 is, the answer is always true.
B1 & B2,
And is only true if all terms are true. Since B2 is false the answer is false.
B1 ^ B2,
XOR is confusing for like the first 30 seconds, or until somebody explains it correctly. As i've stated already, OR is true if any of the terms are true so
(OR)
FALSE | TRUE = TRUE
TRUE | FALSE = TRUE
FALSE | FALSE = FALSE
XOR stands for exclusive OR. And is ONLY true "IF AND ONLY IF" 1 term in the series or equation is true.
(XOR)
TRUE ^ FALSE = TRUE
FALSE ^ TRUE = TRUE
FALSE ^ FALSE = FALSE
TRUE ^ TRUE = FALSE
(remember when you see XOR, say to yourself "IF AND ONLY IF")
Just for people who think they might do some ASM in their future. Some handy uses of xor are...
a XOR 0 = a
a XOR a = 0
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation:
Rep Power: 19
Solved Threads: 200
learn the simple truth tables by heart!
OR |true |false ---------------- true |true |true false|true |false AND |true |false ---------------- true |true |false false|false|false XOR |true |false ---------------- true |false|true false|true |false
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Jul 2005
Posts: 56
Reputation:
Rep Power: 4
Solved Threads: 0
Its either lack of sleep or something but the way u posted this seems a little confusing.
are these in the same format as i used
I'm thinking they are not so what format did you use?
are these in the same format as i used
exp1 (op) exp2 = answer
•
•
•
•
Originally Posted by jwenting
learn the simple truth tables by heart!
OR |true |false ---------------- true |true |true false|true |false AND |true |false ---------------- true |true |false false|false|false XOR |true |false ---------------- true |false|true false|true |false
•
•
Join Date: Jun 2004
Posts: 604
Reputation:
Rep Power: 6
Solved Threads: 6
Hi everyone,
See the below two links
http://www.cafeaulait.org/course/week2/45.html
http://www.sap-img.com/java/java-boo...-operators.htm
I hoped that helped you
Yours Sincerely
Richard West
See the below two links
http://www.cafeaulait.org/course/week2/45.html
http://www.sap-img.com/java/java-boo...-operators.htm
I hoped that helped you
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode