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
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Word | Input | DINT | 80 | Packed word whose existing 1 bits are preserved |
| Cfg_SetMask | Input | DINT | 3 | A 1 forces the matching output bit on |
| Out_Word | Output | DINT | 0 | Input word with selected bits forced on |
Required behavior
- Each bit of Out_Word is 1 when the matching bit of In_Word or Cfg_SetMask is 1.
- A 1 in Cfg_SetMask forces the matching output bit to 1; a 0 preserves the matching In_Word bit.
- Cfg_SetMask can set an input bit but cannot clear one.
- With the defaults, In_Word 80 and Cfg_SetMask 3 produce 83. In Binary their last eight digits are 0101_0000, 0000_0011 and 0101_0011, and every digit before them is 0.
- All 32 bits are evaluated every scan.
- A mask of 0 copies In_Word, while a mask of -1 sets all 32 output bits.