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.

TagValue
Code6
Packed48

Bits 1 and 2 of Code are both on, so bits 4 and 5 of Packed turn on and Packed is 48.

Operands

OperandData typeRead or write
SourceDINT or a numberReads
Source bitDINT or a numberReads
Dest bitDINT or a numberReads
LengthDINT or a numberReads
DestDINTReads 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.