How to write an algorithm to find the number of bits set in a typical number ?

#include <stdio.h> cbs () { unsigned int v; /* count the number of bits set in v */ unsigned int c; /* c accumulates the total bits set in v */ printf(“Enter v”); scanf(“%u”,&v); for (c = 0; v ; c++) { v = v & (v – 1); /* clear the least significant bit …

Hacking the program for counting bits set

$gcc counting-bits-set-naive-way-related.c $./a.out Enter v 8474578 Total bits set in v is 11 $./a.out Enter v 1 Total bits set in v is 1 $./a.out Enter v 2 Total bits set in v is 1 $./a.out 3 Enter v a Total bits set in v is 0 $cat counting-bits-set-naive-way-related.c #include <stdio.h> int main() { unsigned …