Count set bits in an integer | recursive function to count set bits ; base case ; get value from user ; function calling
function countSetBits ( n ) { if ( n == 0 ) return 0 ; else return 1 + countSetBits ( n & ( n - 1 ) ) ; } var n = 9 ; document . write ( countSetBits ( n ) ) ;