| Simulink® | ![]() |
Logic and Bit Operations

The Logical Operator block performs the specified logical operation on its inputs. An input value is TRUE (1) if it is nonzero and FALSE (0) if it is zero.
You select the Boolean operation connecting the inputs with the Operator parameter list. If you select rectangular as the Icon shape property, the block updates to display the name of the selected operator. The supported operations are given below.
| Operation | Description |
|---|---|
AND | TRUE if all inputs are TRUE |
OR | TRUE if at least one input is TRUE |
NAND | TRUE if at least one input is FALSE |
NOR | TRUE when no inputs are TRUE |
XOR | TRUE if an odd number of inputs are TRUE |
NOT | TRUE if the input is FALSE |
If you select distinctive as the Icon shape, the block's appearance indicates its function. Simulink® software displays a distinctive shape for the selected operator, conforming to the IEEE® Standard Graphic Symbols for Logic Functions:

The number of input ports is specified with the Number of input ports parameter. The output type is specified with the Output data type parameter. An output value is 1 if TRUE and 0 if FALSE.
Note The output data type should represent zero exactly. Data types that satisfy this condition include signed and unsigned integers, and any floating-point data type. |
The size of the output depends on input vector size and the selected operator:
If the block has more than one input, any nonscalar inputs must have the same dimensions. For example, if any input is a 2-by-2 array, all other nonscalar inputs must also be 2-by-2 arrays.
Scalar inputs are expanded to have the same dimensions as the nonscalar inputs.
If the block has more than one input, the output has the same dimensions as the inputs (after scalar expansion) and each output element is the result of applying the specified logical operation to the corresponding input elements. For example, if the specified operation is AND and the inputs are 2-by-2 arrays, the output is a 2-by-2 array whose top left element is the result of applying AND to the top left elements of the inputs, etc.
For a single vector input, the block applies the operation (except the NOT operator) to all elements of the vector. The output is always a scalar.
The NOT operator accepts only one input, which can be a scalar or a vector. If the input is a vector, the output is a vector of the same size containing the logical complements of the input vector elements.
When configured as a multi-input XOR gate, this block performs an addition- modulo-two operation as mandated by the IEEE Standard for Logic Elements.
The Logical Operator block accepts real or complex signals of any data type supported by Simulink software, including fixed-point data types.
For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink® in the Simulink documentation.
The Main pane of the Logical Operator block dialog appears as follows:

The logical operator to be applied to the block inputs. Valid choices are the operators listed previously.
The number of block inputs. The value must be appropriate for the selected operator.
The shape of the block icon. Specifying rectangular (the default) results in a rectangular block that displays the name of the selected operator. The distinctive option uses the graphic symbol for the selected operator as specified by the IEEE standard.
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specifying Sample Time in the online documentation for more information.
The Signal Attributes pane of the Logical Operator block dialog appears as follows:

Select to require all inputs and the output to have the same data type.
Specify the output data type. You can set it to:
| Option | Description |
|---|---|
| boolean | Specifies the output data type as boolean. |
| Inherit: Logical | Use the Implement logic signals as boolean data model configuration parameter (see Implement logic signals as boolean data (vs. double)) to specify the output data type. |
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Output
data type parameter.
See Specifying Block Output Data Types for more information.
Note You should use data types that represent zero exactly. Data types that satisfy this condition include signed and unsigned integers and any floating-point data type. |
Direct Feedthrough | Yes |
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | Yes, of inputs |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero Crossing | No |
![]() | Level-2 M-File S-Function | Lookup Table | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |