RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2025 | Replies: 5
Reply
Join Date: Jul 2005
Location: massachusetts
Posts: 12
Reputation: asatrujesus is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
asatrujesus asatrujesus is offline Offline
Newbie Poster

Logical Operator help

  #1  
Jul 21st, 2005
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Logical Operator help

  #2  
Jul 21st, 2005
Read up on boolean logic. The fundamentals are simple but you do need a thorough understanding, more than a short summary can provide.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Jul 2005
Posts: 56
Reputation: Sauce is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Sauce Sauce is offline Offline
Junior Poster in Training

Re: Logical Operator help

  #3  
Jul 24th, 2005
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
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Logical Operator help

  #4  
Jul 25th, 2005
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.
Reply With Quote  
Join Date: Jul 2005
Posts: 56
Reputation: Sauce is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Sauce Sauce is offline Offline
Junior Poster in Training

Re: Logical Operator help

  #5  
Jul 25th, 2005
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?


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
Reply With Quote  
Join Date: Jun 2004
Posts: 604
Reputation: freesoft_2000 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Logical Operator help

  #6  
Jul 25th, 2005
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
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:32 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC