Count set bits · Compiler

Count set bits

A sensor sends a row of binary flags. Each 1 marks one active flag. Count the active flags in the whole row.

Input
One string of 1 to 100 binary digits (0 or 1). Leading zeroes are allowed.
Output
Print the count as a decimal integer.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…