Shop OBEX P1 Docs P2 Docs Learn Events
Bit problem with operator — Parallax Forums

Bit problem with operator

SamTheManSamTheMan Posts: 43
edited 2007-06-14 18:35 in General Discussion
How can I use the operator and(&)·with two·bits?
same with add, sub ,.....
the compiler keep complaining when I try to perform any operation with two bit variables
Example:

x=a and b

where:
x var bit
a var bit
b var bit



·

Comments

  • BeanBean Posts: 8,129
    edited 2007-06-14 18:32
    When the destination is a bit variable, only assignment (=) is allowed.
    The compiler doesn't support any bit operators (mainly because the SX doesn't support them).
    You can assign the bit variables to byte variables and do the operation, or do IF...THEN constructs.

    __PARAM1 = a
    __PARAM2 = b
    __PARAM3 = __PARAM1 AND __PARAM2
    x = __PARAM3.0

    or

    x = 0
    IF a = 1 THEN
    · IF b = 1 THEN
    ··· x = 1
    · ENDIF
    ENDIF

    I know it's not pretty, but it is exactly what the compiler would have to generate anyway.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 8,943
    edited 2007-06-14 18:35
    What this points out is that SX/B is pretty close to the core -- this is what allows it to output clean assembly code that we can all learn from. I've been adding a lot more assembly to my projects, and a lot of those assembly segments start as the compiled output from SX/B that I hand-optimized.
Sign In or Register to comment.