← All exercises

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

TagTypeDefaultDescription
In_WordDINT170Word whose selected bits pass through
Cfg_MaskDINT165A 1 passes the matching input bit; a 0 blocks it
Out_MaskedDINTInput word with every unselected bit cleared

Required behavior