Shop OBEX P1 Docs P2 Docs Learn Events
Question about boolean ">" and "<>" — Parallax Forums

Question about boolean ">" and "<>"

Don MDon M Posts: 1,652
edited 2012-10-05 16:06 in Propeller 1
If I have this case statement:
case (data[i] & $0F00) == $0100

      (data[i] & $00FF) > $0000:
        term.hex(data[i], 4)


and the data pointed to by i is $0000, why does it make it through this (printed)? I also tried using > and I get the same result. What am I not understanding about this boolean logic?

Comments

  • Don MDon M Posts: 1,652
    edited 2012-10-05 15:41
    For that matter why does $0000 even get by this in the first place?
    case (data[i] & $0F00) == $0100   
    
    
  • kuronekokuroneko Posts: 3,623
    edited 2012-10-05 15:49
    Using $0000 the expression (data & $0F00) == $0100 resolves to FALSE. So does (data & $00FF) > $0000. IOW, what you end up with is the equivalent of
    case FALSE
        FALSE: term.hex(data[i], 4)
    
    Most likely not what you want. So what is your intention with all these expressions?

    From the looks of it you want something like this:
    if (data[i] & $0F00) == $0100
        case data[i] & $FF
          $01..$FF: term.dec(data[i], 4)
    
    IOW
    if (data[i] & $0F00) == $0100
        if data[i] & $FF
          term.dec(data[i], 4)
    
  • Don MDon M Posts: 1,652
    edited 2012-10-05 15:56
    If I do it this way then it works better-
        d := data[i] & $0F00  
        case d
          $0100:
            term.hex(data[i], 4)
            term.tx(32)
          other:
            term.hex(data[i], 4)
            term.tx(32)
            term.tx(58)
    
    

    The $0000 is caught in the "other" case and not in the "$0100" case. But I still don't understand the original post question. Can't you combine logic like that?
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-10-05 16:06
    The case statement supports ranges, but not expressions as in your first post. With only two choices if-elseif may be more efficient
    if ((data[i] & $0F00) == $0100)
        term.hex(data[i], 4)
        term.tx(32)
      elseif ((data[i] & $00FF) <> $0000)
        term.hex(data[i], 4)
        term.tx(32)
        term.tx(58)
    
Sign In or Register to comment.