AND vs. &

The BASIC Stamp manual says & is synonomous with AND.

Any ideas why:

if ( (p1_y > (JOY_CENTER - JOY_DEADZONE)) AND (p1_y < (JOY_CENTER + JOY_DEADZONE)) ) then p1_y = 127

works, but:

if ( (p1_y > (JOY_CENTER - JOY_DEADZONE)) & (p1_y < (JOY_CENTER + JOY_DEADZONE)) ) then p1_y = 127

doesn’t?

& is reserved for bit math.

Such as PB_mode.bit0 = PB_mode.bit0 & rc_sw1

Or something along those lines.

First, the Basic Stamp manual says specifically not to use &/AND interchangeably. The difference, like Goya said, is that & is bit-based. For example: 1100110 & 0110011=0100010, wherease 1100110 AND 0110011 is not well-defined. Basically, use AND for combining conditions in IF statements (ie IF rc_sw1=1 AND rc_sw2=0 then doStuff), but use & when doing binary math.

Okay, thank you. Our programmers last year had used “|” for OR in a conditional statement (!), so I started out with the assumption that they were interchangeable, and misconstrued the manual as saying the same thing. I found “Avoiding errors with boolean results” now.