← 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: in Binary, Base 240 ends in 1111_0000, Source 6 in 0000_0110 and Mask 15 in 0000_1111, so the result ends in 1111_0110, which is 246; every digit before those is 0. The same three inputs rebuild the result every scan.

Parameters

TagDirectionTypeDefaultDescription
In_SourceInputDINT6Replacement bits used where the mask is 1
In_BaseInputDINT240Existing word kept where the mask is 0
Cfg_MaskInputDINT15A 1 replaces from Source; a 0 keeps Base
Out_WordOutputDINT0Base word with selected bits replaced

Required behavior