|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#12
|
||||||
|
||||||
|
And one more thing...
Oh yeah, I forgot to answer the basic question from this tread.
If you want to accomplish the equiv. of (Var = XXX) you can do this: bitvarY = (bytevarX = 254) You can do this: bitvarY = 1 - (- ABS(bytevarX - 254) >> 15 ) Again, this is ugly but it accomplishes the result you want without an IF statement. If you are looking to minize code size you may want to try NCD bitvarY = 1 - (- NCD(bytevarX - 254) >> 15) Another hack to try would be to use bitwize XOR for your compare test -- thinking about it, this may be the fastest and tightest way to do it; bitvarY = 1 - ( - (bytevarX ^ 254) >> 15) Yet another thing to try is the Pbasic's normal truncation and the REV function rather than the "-" sign and the ">> 15" business. The whole purpose of these things is to take advantage of all numbers but zero have a negative with a 1 in the high order bit of a 16 bit number. You can get t this bit in an expression using the following as well: bitvarY = ( - (bytevarX ^ 254) REV 16) The above also reverses the sense of bitvarY. It becomes 1 in they are different and 0 if they are equal. This brings up another simplification. Changing bitvarY to the opposite sense (bytevarX <> 254) makes the test a bit easier to implement as all the "1 -" s from the above expressions disappear. Hope this helps. Joe J. |
| 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 |