Go to Post "I don't have a cockroach in my presentation.... " I will remember this line forever. Thank you Autodesk. - Zyik [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Spotlight this post!  
Unread 09-04-2003, 01:19
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
Re: bitwise operators in IF statements

Quote:
Originally posted by WizardOfAz
The manual (Basic_Stamp_Manual_V2-0.pdf, pg 153) says you should not use bitwise operators in IF statements, but when used with awareness of how the bit variables are handled, they seem to work. Can anyone clarify whether what's safe WRT this?
As you said, as long as you understand how bit ops work, you should be fine. However, there are many, many caveats regarding bitwise stuff, so be very careful. Here's some examples:


5 AND 2 will evaluate to true, while
5 & 2 will be false, since 101b & 10b = 000b.

5 AND NOT 2 will evaluate to false, while
5 & ~2 will be true, since 101b & 111111101b=101b=5

Also, as far as I know, the exact value of =, >, <, etc is not officially defined except for the fact that it is zero for false and non-zero for true. Thus, things like:
(5>2) & (3<10)
could evaluate to either true or false, depending on how >, < get evaluated.

In summary, if you know what you're doing and you're only working with bit-sized variables, you can probably get by with the bitwise stuff. Otherwise, I would HIGHLY recommend using the more correct logical operators. It will make your code easier to maintain, easier to understand, and probably more correct.

--Rob

P.S. If anyone knows for sure what =, >, etc evaluate to, I would greatly appreciate knowing in order to fix up RoboEmu. I'm going with the assumption of either 0 or 1 for now, but it could be changed very easily.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
BS2 syntax (PBASIC) on the new controllers? Maybe! Jeremy_Mc Programming 0 25-10-2003 15:00
PBASIC Syntax Question Raven_Writer Programming 4 20-08-2003 08:07
Pbasic 2.5 syntax Rickertsen2 Programming 10 15-02-2003 08:56
Another PBASIC Question Ian W. Programming 4 31-01-2002 21:36
Simplifying PBasic IDiggles General Forum 16 06-11-2001 01:36


All times are GMT -5. The time now is 05:32.

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