BITSUM: Count number of set bits (S7-1500) - STEP 7

FBD (S7-1200, S7-1500)

ft:publication_title
FBD (S7-1200, S7-1500)
Product
STEP 7
Version
V20
Publication date
11/2024
Language
en-US
BITSUM: Count number of set bits

Description

The "Count number of set bits" instruction is used to count the number of bits of an operand that is set to the signal state "1". The operand whose bits are to be counted is specified on the IN parameter. The result of the instruction is output at the RET_VAL parameter.

Parameters

The following table shows the parameters of the "Count number of set bits" instruction:

Parameter

Declaration

Data type

Memory area

Description

EN

Input

BOOL

I, Q, M, D, L, T, C or constant

Enable input

ENO

Output

BOOL

I, Q, M, D, L

Enable output

IN

Input

DWORD

I, Q, M, D, L, P or constant

Operand whose set bits are counted.

RET_VAL

Output

INT

I, Q, M, D, L, P

Number of bits to be set

Example

The following example shows how the instruction works:

The following table shows how the instruction functions using specific values:

Parameter

Operand

Value*

IN

Tag_Input

DW#16#12345678

RET_VAL

Tag_Output

W#16#000D (13 Bits)

*The error codes can be displayed as integer or hexadecimal value in the program editor. You can find information on switching the display formats under "See also".