When all values are boolean doesn’t the binary & operate on more bits than the logical &&?
For example
if ( foo == "Yes" & 2 != 0 & 6 )
or
if ( foo == "Yes" && 2 != 0 && 6 )
(thinking PHP specifically, but any language will do)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How many bits it operates on is irrelevant: the processor can do it in a single instruction anyway (normally). The crucial difference is the shortcut-ability of
&&, so for anything on the right hand side that’s not trivial to evaluate it is faster — assuming a language where&&works this way, like C or Java. (And apparently PHP, though I know to little about it to be sure.)On the other hand, the branch that this shortcut requires might also slow down things, however I’m quite sure nowadays’ compilers are smart enough to optimize that away.