Stateflow    

Binary and Bitwise Operations

The table that follows summarizes the interpretation of all binary operators in Stateflow action language. Table order gives relative operator precedence; highest precedence (10) is at the top of the table. Binary operators are evaluated left to right (left associative).

If you select the Enable C-like bit operations check box in the properties dialog for the chart (see the section Specifying Chart Properties), some of the binary operators are interpreted as bitwise operators. See individual operators in the table that follows for specific binary or bit operator interpretations.

Example
Precedence
Description
a * b
10
Multiplication
a / b
10
Division
a %% b
10
Modulus
a + b
9
Addition
a - b
9
Subtraction
a >> b
8
Shift operand a right by b bits. Noninteger operands for this operator are first cast to integers before the bits are shifted.
a << b
8
Shift operand a left by b bits. Noninteger operands for this operator are first cast to integers before the bits are shifted.
a > b
7
Comparison of the first operand greater than the second operand
a < b
7
Comparison of the first operand less than the second operand
a >= b
7
Comparison of the first operand greater than or equal to the second operand
a <= b
7
Comparison of the first operand less than or equal to the second operand
a == b
6
Comparison of equality of two operands
a ~= b
6
Comparison of inequality of two operands
a != b
6
Comparison of inequality of two operands
a <> b
6
Comparison of inequality of two operands
a & b
5
One of the following:
  • Bitwise AND of two operands
  • Logical AND of two operands
  • Enabled when Enable C-like bit operations is cleared in chart properties dialog.

a ^ b
4
One of the following:
  • Bitwise XOR of two operands
  • Operand a raised to power b
  • Enabled when Enable C-like bit operations is cleared in chart properties dialog.

    Use parentheses around power expressions with the ^ operator when used in conjunction with other arithmetic operators to avoid problems with operator precedence. For example, the action z=x^2+y^2 should be rewritten as z=(x^2)+(y^2).

a | b
3
One of the following:
  • Bitwise OR of two operands
  • Logical OR of two operands
  • Enabled when Enable C-like bit operations is cleared in chart properties dialog.

a && b
2
Logical AND of two operands
a || b
1
Logical OR of two operands


  Operations Unary Operations