← All courses

Bit Manipulation

Pack, mask and modify integer words

Read and build packed device registers, then use masks to keep, force, replace or remember selected bits without disturbing the rest of the word.

  1. 0

    Outputs the bitwise complement of an integer input — every bit flipped.

    Word Invert

    EXERCISE
    Difficultyeasy
    Statusunknown
  2. 1

    Outputs a word whose bits are set only where the command and feedback words disagree.

    Bit Difference

    EXERCISE
    Difficultyeasy
    Statusunknown
  3. 2

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

    Bit Pack

    EXERCISE
    Difficultyeasy
    Statusunknown
  4. 3

    Unpacks the low eight bits of a DINT word into eight BOOL outputs.

    Bit Unpack

    EXERCISE
    Difficultyeasy
    Statusunknown
  5. 4

    Combines two 16-bit device registers into one 32-bit word.

    Combine Two Registers

    EXERCISE
    Difficultymedium
    Statusunknown
  6. 5

    Reads a 16-bit register from a device that sends its high byte first.

    Swap Register Bytes

    EXERCISE
    Difficultyeasy
    Statusunknown
  7. 6

    Reads a REAL that a Modbus device sends in two registers, high word first.

    REAL From Two Registers

    EXERCISE
    Difficultymedium
    Statusunknown
  8. 7

    Sends a REAL to a device that reads 32-bit values highest byte first.

    REAL in Network Byte Order

    EXERCISE
    Difficultymedium
    Statusunknown
  9. 8

    Passes only the input bits selected by a mask; every unselected output bit is zero.

    Apply Bit Mask

    EXERCISE
    Difficultyeasy
    Statusunknown
  10. 9

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

    Set Selected Bits

    EXERCISE
    Difficultyeasy
    Statusunknown
  11. 10

    Replaces selected bits in an existing word while preserving every unselected bit.

    Replace Selected Bits

    EXERCISE
    Difficultymedium
    Statusunknown
  12. 11

    Copies selected source bits into a retained word while preserving its previous unselected bits.

    Stateful Masked Move

    EXERCISE
    Difficultymedium
    Statusunknown
  13. 12

    Flips the masked bits of a retained word on each rising edge of the toggle command.

    Bit Toggle

    EXERCISE
    Difficultymedium
    Statusunknown
  14. 13

    Works out which byte order a device uses from a value it is known to report.

    Detect the Byte Order

    EXERCISE
    Difficultyhard
    Statusunknown
  15. End