Number of mismatching bits in the binary representation of two integers | Compute number of different bits ; Since , the numbers are less than 2 ^ 31 run the loop from '0' to '31' only ; Right shift both the numbers by ' i ' and check if the bit at the 0 th position is different ; Driver code ; Find number of different bits
function solve ( A , B ) { var count = 0 ; for ( i = 0 ; i < 32 ; i ++ ) { if ( ( ( A >> i ) & 1 ) != ( ( B >> i ) & 1 ) ) { count ++ ; } } document . write ( " " + count ) ; } var A = 12 , B = 15 ; solve ( A , B ) ;