Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   AND vs. & (http://www.chiefdelphi.com/forums/showthread.php?t=17255)

n[ate]vw 01-02-2003 14:21

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?

Goya 01-02-2003 14:47

& is reserved for bit math.

Such as PB_mode.bit0 = PB_mode.bit0 & rc_sw1

Or something along those lines.

rbayer 01-02-2003 16:36

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.

n[ate]vw 01-02-2003 17:39

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.


All times are GMT -5. The time now is 04:29.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi