Stateflow User's Guide Previous page   Next Page

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).

You can specify that the binary operators &, ^, |, &&, and || are interpreted as bitwise operators in Stateflow generated C code for a chart or for all the charts in a model. See these individual operators in the table that follows for specific binary or bitwise 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-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-bit operations is cleared in chart properties dialog.

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

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


Previous page  Using Operations in Actions Unary Operations Next page

© 1994-2005 The MathWorks, Inc.