Apply Bit Mask
easy
Passes only the input bits selected by a mask; every unselected output bit is zero.
What it teaches
Think of the mask as a stencil over the input word: a 1 lets that input bit through, while a 0 blocks it. Example: in Binary, input 170 ends in 1010_1010 and mask 165 in 1010_0101, so the result ends in 1010_0000, which is 160; every digit before those is 0. The everyday job is extraction: mask a packed status word and you are left holding just the field you care about — the fault code, the mode bits — with everything else stripped to zero.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Word | Input | DINT | 170 | Word whose selected bits pass through |
| Cfg_Mask | Input | DINT | 165 | A 1 passes the matching input bit; a 0 blocks it |
| Out_Masked | Output | DINT | 0 | Input word with every unselected bit cleared |
Required behavior
- Each bit of Out_Masked is 1 only when the matching bits of In_Word and Cfg_Mask are both 1.
- A 1 in Cfg_Mask lets the matching In_Word bit pass; a 0 forces that output bit to 0.
- All 32 bits are evaluated every scan.
- With the defaults, In_Word 170 and Cfg_Mask 165 produce 160. In Binary their last eight digits are 1010_1010, 1010_0101 and 1010_0000, and every digit before them is 0.
- A mask of 0 produces 0, while a mask of -1 passes all 32 bits of In_Word.