Shop OBEX P1 Docs P2 Docs Learn Events
BS1 equation in one line — Parallax Forums

BS1 equation in one line

Hello parallax experts!
Is there any way to make this equation in one line using the BS1 ?
B = timer - (A * 10)
It does not allow me to do that.
The value of timer is 35 and the value of A is 3.
The result should be equal to 5:
B = 35 - 30 = 5
Is there any way to do it?
Thanks

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2021-11-15 03:22

    -a * 10 + timer

    (maybe; not a BS1 guru here)

    -Phil

  • Mmmm It doesn’t make sense to me but I will give it a try! Thanks

    @"Phil Pilgrim (PhiPi)" said:
    -a * 10 + timer

    (maybe; not a BS1 guru here)

    -Phil

    @"Phil Pilgrim (PhiPi)" said:
    -a * 10 + timer

    (maybe; not a BS1 guru here)

    -Phil

  • Luis_P,

    Page 103 (PDF Page 107) of the BASIC Stamp Manual says:

    The BS1 does not allow parenthesis in expressions. Unfortunately, all
    expressions have to be written so that they evaluate as intended strictly
    from left to right.
    

    https://www.parallax.com/package/basic-stamp-manual/

  • @"Phil Pilgrim (PhiPi)" said:
    -a * 10 + timer

    (maybe; not a BS1 guru here)

    -Phil

    That works!!!!! Thank you very much!!!! I don’t understand how but is what I was looking for.
    Luis

  • The original parentheses indicated to do the multiplication first, before the subtraction. The new formula rearranges things so that this can be accomplished left-to-right, without the parens.

    -Phil

  • JonnyMacJonnyMac Posts: 9,102
    edited 2021-11-15 22:33

    That works!!!!! Thank you very much!!!! I don’t understand how but is what I was looking for.

    There is no operator precedence with the BS1; as stated, expressions are evaluated from left to right.

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2021-11-16 01:18

    Lack of precedence for binary operators is also true of the BASIC Stamp 2, however, unlike the Stamp 1, the Stamp 2 does allow parentheses to change the order. So B = timer - (A * 10) works okay on the Stamp2, but without parens it would come out wrong and would have to be written like Phil suggested. B = -A * 10 + timer, strictly left to right execution. It could also be B = A * -10 + timer, because unary operators do take precedence over binary operators on either Stamp. Parentheses do make things a lot easier on the Stamp2,

  • Thank you to all of you. Now I understand how it works on the BS1!

    Grazie!

    @"Tracy Allen" said:
    Lack of precedence for binary operators is also true of the BASIC Stamp 2, however, unlike the Stamp 1, the Stamp 2 does allow parentheses to change the order. So B = timer - (A * 10) works okay on the Stamp2, but without parens it would come out wrong and would have to be written like Phil suggested. B = -A * 10 + timer, strictly left to right execution. It could also be B = A * -10 + timer, because unary operators do take precedence over binary operators on either Stamp. Parentheses do make things a lot easier on the Stamp2,

Sign In or Register to comment.