
-----------------------------------
raptors892004
Tue Nov 14, 2006 11:35 am

&amp;&amp; vs &amp; and || vs |
-----------------------------------
I'm sorry if this may seem as kind of a dumb question but I always keep forgeting about this. What is the difference between && and & and || and | ? I know one checked all conditions regardless if one of them was broken but which one is it?

I want my program to check 3 values and if one of them is incorrect (does not equal a supplied default one) then it goes to execute different code.

Thanks for any replies in advance.

-----------------------------------
wtd
Tue Nov 14, 2006 12:24 pm


-----------------------------------
&& and || are logical.  The others work on a bitwise basis.

-----------------------------------
raptors892004
Tue Nov 14, 2006 4:16 pm


-----------------------------------
&& and || are logical.  The others work on a bitwise basis.

So what is the difference between && and & (it would be the same for || and |)? That was my question (I may have not expressed it too clearly though).

-----------------------------------
Andy
Tue Nov 14, 2006 4:25 pm


-----------------------------------
okay, bitwise or will or every single bit of two given binary strings. where as logical or will only give you 0 or 1

-----------------------------------
andy_tok
Tue Nov 14, 2006 4:54 pm


-----------------------------------
&& and || are short-circuits while & and | are not.
Sometimes short-circuit is useful.
Exp. (x!=0)&&(x++>10)
       if x is 0, then the increment will not occur
       if you want x++ to be implemented in all situations then use (x!=0)&(x++>10)

-----------------------------------
Andy
Tue Nov 14, 2006 5:13 pm


-----------------------------------
the short circuit aspect is a result of bitwise/logical characteristics. it's not by itself, a specific feature.

-----------------------------------
r.3volved
Tue Nov 14, 2006 6:55 pm


-----------------------------------
Basically what they're telling you is to look up the difference between, and definitions for bitwise and logical operators. You won't understand what they're used for if you don't understand why they're used.

Links:
http://www.quepublishing.com/articles/article.asp?p=101368&seqNum=5&rl=1
http://www.janeg.ca/scjp/oper/bitwiseAndLogical.html
http://www.janeg.ca/scjp/oper/bitwise.html
http://www.janeg.ca/scjp/oper/logical.html

-----------------------------------
raptors892004
Tue Nov 14, 2006 10:10 pm


-----------------------------------
Thank you very much for the help once again. Those websites were really useful :)

-----------------------------------
r.3volved
Tue Nov 14, 2006 10:34 pm


-----------------------------------
Damn straight
I run shit  8-) 
*toot* (my horn) *toot*
