text: Hamming distance between two Integers | C # implementation of above approach ; Function to calculate hamming distance ; Driver code
code: class GFG { static int hammingDistance ( int n1 , int n2 ) { int x = n1 ^ n2 ; int setBits = 0 ; while ( x > 0 ) { setBits += x & 1 ; x >>= 1 ; } return setBits ; } static void Main ( ) { int n1 = 9 , n2 = 14 ; System . Console . WriteLine ( hammingDistance ( n1 , n2 ) ) ; } }