 FP_COUNT_TRUE_BITS
FP_COUNT_TRUE_BITSNumber of ON bits
This FP instruction counts the number of bits which are TRUE in the data specified by s if the trigger EN is TRUE. The result is stored in d.

Input
Input value
Output
Number of bits which are TRUE in the argument applied at s
if the area specified using the index modifier exceeds the limit.
if the area specified using the index modifier exceeds the limit.

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		bStart: BOOL:=FALSE;
			(*activates the function*)
		dwChecked_value: DWORD:=16#1111FFFF;
			(*this value will be checked
for ON-bits*)
		iOutput_value: INT:=0;
			(*result after a 0->1 leading
edge from start: 20*)
	END_VARWhen the variable bStart is set to TRUE, the function is carried out. The number of bits which are TRUE in the binary equivalent of 16#1111FFFF is 20.


BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,FP_COUNT_TRUE_BITS!,,15,1,27,5,,?DEN?D@'s'?AENO?Cd);
B(B_CONTACT,,bStart,10,2,12,4,);
B(B_VARIN,,dwChecked_value,13,3,15,5,);
B(B_VAROUT,,iOutput_value,27,3,29,5,);
L(1,3,10,3);
L(12,3,15,3);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY
IF bStart then
    FP_COUNT_TRUE_BITS(s := dwChecked_value, d => iOutput_value);
END_IF;