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.

Recommended Answers

All 5 Replies

Read up on boolean logic. The fundamentals are simple but you do need a thorough understanding, more than a short summary can provide.

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

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

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

exp1 (op) exp2 = answer

I'm thinking they are not so what format did you use?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.