C # implementation of the above approach
using System ; class GFG { static int TOTAL_BITS = 32 ; static int CountBits ( int value ) { int count = 0 ; while ( value != 0 ) { count ++ ; value &= value - 1 ; } return count ; }