Function to calculate and return the hamming distance between all consecutive numbers from 0 to N
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 ; }