|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#8
|
||||||
|
||||||
|
Re: bitwise operators in IF statements
Quote:
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. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |