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)
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.