← Bit Manipulation

Set Selected Bits

easy

Forces selected bits of a word on while preserving every other input bit.

What it teaches

Use an OR mask to add required flags to a packed command word without clearing flags already present. A 1 in the mask forces that bit on; a 0 leaves the matching input bit unchanged. Example: in Binary, input 80 ends in 0101_0000 and mask 3 in 0000_0011, so the result ends in 0101_0011, which is 83; every digit before those is 0. The mirror trick — forcing selected bits off — is an AND with the inverted mask.

Parameters

TagDirectionTypeDefaultDescription
In_WordInputDINT80Packed word whose existing 1 bits are preserved
Cfg_SetMaskInputDINT3A 1 forces the matching output bit on
Out_WordOutputDINT0Input word with selected bits forced on

Required behavior