[OT] help w/ bitwise comparison operators

Erik Price eprice at ptc.com
Fri Mar 21 14:27:01 EST 2003


Kevin D. Clark wrote:
> 
> Erik Price <eprice at ptc.com> writes:
> 
> 
>>The short circuit operators AND (&&) and OR (||) work just like their
> 
>                                                         ^^^^^^^^^^^^^^^
> 
>>regular counterparts except they stop evaluating once they "know" the
>>result (AND stops evaluating if the first operand is false, and OR
>>stops evaluating if the first operand is true).
> 
> 
> You might be interested to know that (1 & 2) results in 0 wheras 
> (1 && 2) results in something non-zero...
> 
> Remember, operators like '&' are bit operators, wheras operators like
> '&&' are logical operators.  These are very different.

You're right, thanks for the correction.  I mis-read the text.  &, |, 
&&, and || are all -logical- operators, and what I said above is true 
only for boolean values.  The short-circuit logical operators (&& and 
||) won't compile if they are used with integral operands, though the 
bitwise operators (& and |) will.


Erik




More information about the gnhlug-discuss mailing list