K&R Exercises

Exercise 2-9: Faster bit count

In a two's complement number system, x &= (x-1) deletes the rightmost 1-bit in x. Explain why. Use this observation to write a faster version of bitcount.

Each input line holds an unsigned number in decimal. Print bitcount of it on a line of its own.

Test Cases

· space→ tab↵ newline

Submissions

No submissions yet