intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF

int e l 5.3 UNDERSTANDING PRECEDENCE OF OPERATORS The hierarchy of mathematics dictates that some operations are carried out before others. If you understand the hierarchy of mathematics, it is possible to write complex expressions using only a minimum amount of parentheses. It is easy to illustrate what precedence is all about, examine the following equation: 4+3*2 = ? Should you add (4+3) then multiply seven by 2, or should you multiply (3*2) then add 4? Well, the hierarchy of mathematics says that multiplication has precedence over addition, so you would multiply (3*2) first then add 4, So, 4+3*2 = 10 The rules for the hierarchy of math are simple.

When an expression is scanned from left to right an operation is not performed until an operator of lower or equal precedence is encountered. In the example addition could not be performed because multiplication has higher precedence. The precedence of operators from highest to lowest in MCS BASIC-52 is as follows: 1) OPERATORS THAT USE PARENTHESES ( ) 2) EXPONENTATION (**) 3) NEGATION (-) 4) MULTIPLICATION (*) AND DIVISION (/) 5) ADDITION (+) AND SUBTRACTION (-) 6) RELATIONAL EXPRESSIONS (=, , >, >=, 7) LOGICAL AND (.AND.) 8) LOGICAL OR (.OR.) 9) LOGICAL XOR (.XOR.) Relative to operator precedence, the rule of thumb should always be, when in doubt, use parentheses. - 80 -