TIA Anzahl gesetzter Bits

statusbass

Level-1
Beiträge
12
Reaktionspunkte
1
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo
ich würde gerne abfragen wieviele Bits in einem doppelword gesetzt (true) sind. Mit Bitsum ist das ja problemlos möglich, allerdings nur bis zu einem Doppelwort und nicht bei S7-1200.
Ich habe 6 DW und eben die S7-1200.
Hat jemend eine Idee, am besten in scl.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Beispiel für Bitsum für die 1200:
Code:
FUNCTION "CountBitsInDWord" : Int
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      In : DWord;
   END_VAR

BEGIN
	#CountBitsInDWord := BOOL_TO_INT(#In.%X0) + BOOL_TO_INT(#In.%X1) + BOOL_TO_INT(#In.%X2) + BOOL_TO_INT(#In.%X3) +
	BOOL_TO_INT(#In.%X4) + BOOL_TO_INT(#In.%X5) + BOOL_TO_INT(#In.%X6) + BOOL_TO_INT(#In.%X7) +
	BOOL_TO_INT(#In.%X8) + BOOL_TO_INT(#In.%X9) + BOOL_TO_INT(#In.%X10) + BOOL_TO_INT(#In.%X11) +
	BOOL_TO_INT(#In.%X12) + BOOL_TO_INT(#In.%X13) + BOOL_TO_INT(#In.%X14) + BOOL_TO_INT(#In.%X15) +
	BOOL_TO_INT(#In.%X16) + BOOL_TO_INT(#In.%X17) + BOOL_TO_INT(#In.%X18) + BOOL_TO_INT(#In.%X19) +
	BOOL_TO_INT(#In.%X20) + BOOL_TO_INT(#In.%X21) + BOOL_TO_INT(#In.%X22) + BOOL_TO_INT(#In.%X23) +
	BOOL_TO_INT(#In.%X24) + BOOL_TO_INT(#In.%X25) + BOOL_TO_INT(#In.%X26) + BOOL_TO_INT(#In.%X27) +
	BOOL_TO_INT(#In.%X28) + BOOL_TO_INT(#In.%X29) + BOOL_TO_INT(#In.%X30) + BOOL_TO_INT(#In.%X31);
	
END_FUNCTION
 
Zurück
Oben