text: Sum of Hamming difference of consecutive numbers from 0 to N | Set 2 | Function to calculate and return the hamming distance between all consecutive numbers from 0 to N ; Driver Code
code: function TotalHammingDistance ( n ) { let i = 1 , sum = 0 ; while ( Math . floor ( n / i ) > 0 ) { sum = sum + Math . floor ( n / i ) ; i = i * 2 ; } return sum ; } let N = 9 ; document . write ( TotalHammingDistance ( N ) ) ;