Sum of bit differences for numbers from 0 to N | Set 2 | Recursive function to find sum of different bits between consecutive numbers from 0 to N ; Base case ; Calculate the Nth term ; Given number ; Function call
function totalCountDifference ( n ) { if ( n == 1 ) return 1 ; return n + totalCountDifference ( Math . floor ( n / 2 ) ) ; } let N = 5 ; document . write ( totalCountDifference ( N ) ) ;