BS1 equation in one line
Luis_P
Posts: 246
in BASIC Stamp
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
-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
Luis_P,
Page 103 (PDF Page 107) of the BASIC Stamp Manual says:
https://www.parallax.com/package/basic-stamp-manual/
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
There is no operator precedence with the BS1; as stated, expressions are evaluated from left to right.
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!