Exercism c++ problem

BTW, Was this an Arduino problem, or general C/C++ ?

Implementing something efficient will depend on CPU architecture; for example there are fancy shift and add algorithms that would suck on AVR because it can only shift one bit at a time...

If this is a beginner CS class, it would be very impressive for any of the students to come up with anything other than counting individual bits. And it might be that that's the desired implementation, since it uses "more" of the "basic bitwise operations" in C/C++ than some of the "advanced" methods.

Anything more complex smacks of "research"; that's not necessarily a bad thing, and there are a bunch of bit-counting algorithms that are well documented that you can find (again: architecture dependent.) But the teacher may well want you to figure out a more basic algorithm all on your own.

I'll note that the original problem doesn't specify the "size" of the number; watch out for that...

Using recursion or division for this is sick :frowning: