Bit Manipulation

Replace Selected Bits

medium

Replaces selected bits in an existing word while preserving every unselected bit.

What it teaches

Unlike Apply Bit Mask, a blocked position does not become 0: it comes from a separate Base word. A 1 replaces that position with the Source bit; a 0 keeps the Base bit. Example: Base 240 is 1111 0000, Source 6 is 0000 0110, and Mask 15 is 0000 1111, so the result is 1111 0110, or 246. The same three inputs rebuild the result every scan.

Inputs and outputs

TagTypeDefaultDescription
In_SourceDINT6Replacement bits used where the mask is 1
In_BaseDINT240Existing word kept where the mask is 0
Cfg_MaskDINT15A 1 replaces from Source; a 0 keeps Base
Out_WordDINTBase word with selected bits replaced

Required behavior