|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#7
|
|||||
|
|||||
|
bitwise operators in IF statements
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?
For example '(note all variables in these code snippets are single bits) b1 var bit b2 var bit if (b1 & b2) then appears to behave equivalently to if (b1=1) and (b2=1) then And produces smaller code, which is the goal of this question. Also... though it's understandable if unfortunate that you don't get what you might expect when you code if (~b1) then since ~b1 will always evaluate to %11111111111111x and therefore always be true regardless of the value of the bit stored in b1. Seems like if (b1 & ~b2) then Will give the expected and desired result since the leading zeros in b1 will mask off the leading ones in b2, and the result will depend only on the logical & of the single variable bits. Again, this produces smaller code than does if (b1=1) and (b2=0) then Any feedback? Bill |
| 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 |