BS1 equation in one line — Parallax Forums

# BS1 equation in one line

Posts: 156

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

• Posts: 23,493
edited 2021-11-15 03:22

-a * 10 + timer

(maybe; not a BS1 guru here)

-Phil

• Posts: 156

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

• Posts: 1,695

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/

• Posts: 156

@"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

• Posts: 23,493

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

• Posts: 8,318
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.

• Posts: 6,641
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,

• Posts: 156

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,