I am looking for a fast algorithm to do the following task: Given $N$ numbers $a_i, i=1,..., N$, where $a_i$ can be equal to $0$ or $1$, compute the number $s \equiv \sum_{i=1}^N a_i$ in base 2. Example: $N=3$, $a_1=0,a_2=a_3=1$, $s=10$.
There is a naif algorithm to do this task: take $a_1$, then compute $a_1+a_2$ in base $2$ by adding bit-by-bit $a_2$ to $a_1$ and by taking care of the carry, then sum $a_3$ to $a_1+a_2$ in the same way, etc... until the sum $s$ is computed.
Do you know an algorithm that can do this task in a fewer number of operations than the naif algorithm? Any improvement over the naif algorithm would be fine for me.
Thank you Best, Michele