Go to Post There can be only one.... - Koko Ed [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-02-2003, 14:21
n[ate]vw's Avatar
n[ate]vw n[ate]vw is offline
Registered User
#0933 (Adler Attack)
 
Join Date: Jan 2003
Location: Rockford, IL
Posts: 48
n[ate]vw is an unknown quantity at this point
Send a message via AIM to n[ate]vw
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?
__________________
Adler Attack #933 -- Trigos
  #2   Spotlight this post!  
Unread 01-02-2003, 14:47
Goya Goya is offline
Registered User
#0019 (Big Red)
 
Join Date: Jan 2003
Location: Greenwich, CT
Posts: 35
Goya is an unknown quantity at this point
Send a message via AIM to Goya
& is reserved for bit math.

Such as PB_mode.bit0 = PB_mode.bit0 & rc_sw1

Or something along those lines.
  #3   Spotlight this post!  
Unread 01-02-2003, 16:36
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
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.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #4   Spotlight this post!  
Unread 01-02-2003, 17:39
n[ate]vw's Avatar
n[ate]vw n[ate]vw is offline
Registered User
#0933 (Adler Attack)
 
Join Date: Jan 2003
Location: Rockford, IL
Posts: 48
n[ate]vw is an unknown quantity at this point
Send a message via AIM to n[ate]vw
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.
__________________
Adler Attack #933 -- Trigos
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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