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: input 170 is 1010 1010, mask 165 is 1010 0101, so the result is 1010 0000, or 160. 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.
Inputs and outputs
| Tag | Type | Default | Description |
|---|---|---|---|
| In_Word | DINT | 170 | Word whose selected bits pass through |
| Cfg_Mask | DINT | 165 | A 1 passes the matching input bit; a 0 blocks it |
| Out_Masked | DINT | — | 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 (1010 1010) and Cfg_Mask 165 (1010 0101) produce 160 (1010 0000).
- A mask of 0 produces 0, while a mask of -1 passes all 32 bits of In_Word.