Shop OBEX P1 Docs P2 Docs Learn Events
Help with Operators in Spin — Parallax Forums

Help with Operators in Spin

Chris MerckChris Merck Posts: 55
edited 2009-06-16 23:00 in Propeller 1
To the best of my knowledge the following lines of spin should be equivalent (where f is a long and a and b are constants in the range 0..31):

if f&|<a AND f&|<b
  ...





if f&(|<a | |<b)
 ...




However, these two lines give different behavior.

The interpretation here is that a and b are the names of bits in the flag register f, and the if-block is to be executed if both flags a and b are set.

Something must be wrong with how I am thinking about these operators. Can anyone clarify this?

Thanks,
Chris

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2009-06-16 04:11
    The second one evaluates to non-zero (which propagates to TRUE) when either of the flags is set. You probably want something like

    if (f&constant(|<a | |<b)) == constant(|<a | |<b)
    
  • Chris MerckChris Merck Posts: 55
    edited 2009-06-16 04:13
    kuroneko,
    Thanks for the fast response. You are totally right. I can't believe I missed that. (This has been bugging me for 2 hours).
  • VGVG Posts: 32
    edited 2009-06-16 20:29
    I think the following should also work.
    if·f & (|<a·& |<b)
    ··...

    Please correct me if I am wrong.

    Sincerely,
    Venkata.
  • Chris MerckChris Merck Posts: 55
    edited 2009-06-16 23:00
    f & (|<a & |<b) will be true only when a=b and f.a=1
Sign In or Register to comment.