Distribute bits BIT FIELD
Copies Length bits of Source into Dest at Dest bit.
How it works
While the rung is true, copies Length bits of Source, starting at Source bit, into Dest, starting at Dest bit. Every other bit of Dest stays as it was. Bits count from 0, and a field must fit in 32 bits; one that does not is a fault and leaves Dest unchanged.
How it's used
Use it to pack a small number into part of a word, such as a 2-bit mode into bits 4 and 5.
DISTRIBUTE_BITS
SourceGlobal.Code6Src Bit1Dest Bit4Length2DestGlobal.Packed48
| Tag | Value |
|---|---|
| Code | 6 |
| Packed | 48 |
Bits 1 and 2 of Code are both on, so bits 4 and 5 of Packed turn on and Packed is 48.
Operands
| Operand | Data type | Read or write |
|---|---|---|
| Source | DINT or a number | Reads |
| Source bit | DINT or a number | Reads |
| Dest bit | DINT or a number | Reads |
| Length | DINT or a number | Reads |
| Dest | DINT | Reads and writes |
Common mistakes
- Counting bits from 1Bits count from 0, so bit 4 is the fifth bit. Dest bit plus Length must be 32 or less.