← All exercises

Bit Pack

easy

Packs eight BOOL inputs into the low eight bits of one DINT word.

What it teaches

Build a packed word by clearing it, then writing each BOOL directly to its matching bit address: In_00 controls bit 0 through In_07 controlling bit 7. Clearing first guarantees bits 8-31 are 0 instead of retaining stale data.

Inputs and outputs

TagTypeDefaultDescription
In_00BOOL
In_01BOOL
In_02BOOL
In_03BOOL
In_04BOOL
In_05BOOL
In_06BOOL
In_07BOOL
Out_WordDINTPacked input bits; bits 8-31 are 0

Required behavior

  • Each input maps to one bit of Out_Word: In_00 drives bit 0 through In_07 driving bit 7.
  • Out_Word is cleared and bits 0-7 are rebuilt from the inputs every scan.
  • Bits 8-31 of Out_Word are always 0.