text: Hamming distance between two Integers | Function to calculate hamming distance ; Driver code
code: function hammingDistance ( n1 , n2 ) { let x = n1 ^ n2 ; let setBits = 0 ; while ( x > 0 ) { setBits += x & 1 ; x >>= 1 ; } return setBits ; } let n1 = 9 , n2 = 14 ; document . write ( hammingDistance ( 9 , 14 ) ) ;