|
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.
|