[?]: Display number of digital inputs

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Frz 1995
Posts: 1
Joined: Sat Feb 20, 2021 9:48 am

[?]: Display number of digital inputs

Post by Frz 1995 »

In the step 7 s300 (with fbd or ladder) write a program that display number of true digital inputs of a card with 16 inputs in every moment.
MaxS
Posts: 62
Joined: Sat May 17, 2014 1:26 am

Re: [?]: Display number of digital inputs

Post by MaxS »

Henry S. Warren, Jr. - Hacker’s Delight (Second Edition)
Chapter 5. Counting Bits

For 16 bits:

Code: Select all

  x = (x & 0x5555) + ((x>>1) & 0x5555);
  x = (x & 0x3333) + ((x>>2) & 0x3333);
  x = (x & 0x0F0F) + ((x>>4) & 0x0F0F);
  x = (x & 0x00FF) + ((x>>8) & 0x00FF);
  return x;
SIMATIC Step 7 (FBD)
Show
Image