The following is pseudocode, don't take it too literal allthough I guess it will probably run ;-) (* DECLARATION *) VAR size, i : INT; Bitcount : INT := 0; CurBoolVal : BOOL; TheWordIWantToCheck : WORD; END_VAR (* CODE *) size := SIZE_OF(TheWordIWantToCheck); (* dependends on processor memory width but I assume 16 for now *) FOR i := 0 TO size - 1 DO (* eg. count bit 0 to 15 *) CurBoolVal := TheWordIWantToCheck.i; (* Helper to cast Bit i to Bool *) BitCount := BitCount + BOOL_TO_INT(CurBoolVal);...
The following is pseudocode, don't take it too literal allthough I guess it will probably run ;-) (* DECLARATION *) VAR size, i : INT; Bitcount : INT := 0; CurBoolVal : BOOL; TheWordIWantToCheck : WORD; END_VAR (* CODE *) size := SIZE_OF(TheWordIWantToCheck); (* dependends on processor memory width but I assume 16 for now *) FOR i := 0 TO size - 1 DO (* eg. count bit 0 to 15 *) CurBoolVal := TheWordIWantToCheck.i; (* Helper to cast Bit to Bool *) BitCount := BitCount + BOOL_TO_INT(CurBoolVal); (*...