| Simulink Reference | ![]() |
Perform the specified bitwise operation on the inputs
Library
Description
The Bitwise Operator block performs the specified bitwise operation on its operands.
Unlike the logic operations performed by the Logical Operator block, bitwise operations treat the operands as a vector of bits rather than a single number. You select the bitwise Boolean operation from the Operator parameter list. The supported operations are given below.
The Bitwise Operator block does not support shift operations. For shift operations, see the Shift Arithmetic block.
The size of the output of the Bitwise Operator block depends on the number of inputs, their vector size, and the selected operator:
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.
If you do not select the Use bit mask check box, then the block can accept multiple inputs. You select the number of input ports from the Number of input ports parameter. The input data types must be identical.
If you select the Use bit mask check box, then a single input is associated with the bit mask you specify from the Bit Mask parameter. You specify the bit mask using any valid MATLAB expression. For example, you can specify the bit mask 00100101 as 2^5+2^2+2^0. Alternatively, you can use strings to specify a hexadecimal bit mask such as {'FE73','12AC'}. If the bit mask is larger than the input signal data type, then it is ignored.
The Treat mask as parameter list controls how the mask is treated. The possible values are Real World Value and Stored Integer. In terms of the general encoding scheme described in the Scaling section of the Simulink Fixed Point documentation, Real World Value treats the mask as V = SQ + B where S is the slope and B is the bias. Stored Integer treats the mask as a stored integer, Q.
You can use the bit mask to perform a bit set or a bit clear on the input. To perform a bit set, set the Operator parameter list to OR and create a bit mask with a 1 for each corresponding input bit that you want to set to 1. To perform a bit clear, set the Operator parameter list to AND and create a bit mask with a 0 for each corresponding input bit that you want to set to 0.
For example, suppose you want to perform a bit set on the fourth bit of an 8-bit input vector. The bit mask would be 00010000, which you can specify as 2^4 in the Bit mask parameter. To perform a bit clear, the bit mask would be 11101111, which you can specify as 2^7+2^6+2^5+2^3+2^2+2^1+2^0 in the Bit mask parameter.
Data Type Support
The Bitwise Operator block supports Simulink integer, fixed-point, and Boolean data types. The block does not support true floating-point data types.
Parameters and Dialog Box
Examples
To help you understand the Bitwise Operator block logic operations, consider the fixed-point model shown below.

The Constant blocks are configured to output an 8-bit unsigned integer (uint(8)). The results for all logic operations are shown below.
| Operation |
Binary Value |
Decimal Value |
| AND |
00101000 |
40 |
| OR |
11111101 |
253 |
| NAND |
11010111 |
215 |
| NOR |
00000010 |
2 |
| XOR |
11111000 |
248 |
| NOT |
N/A |
N/A |
Characteristics
| Direct Feedthrough |
No |
| Scalar Expansion |
Yes, of inputs |
| Bit Set | Bus Assignment | ![]() |
© 1994-2005 The MathWorks, Inc.