Created
October 15, 2016 14:00
-
-
Save priyanshujain/0db0bc44a3abdeffb915e4cff6f46efb to your computer and use it in GitHub Desktop.
number of bits that are different between two numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main(int argc, char const *argv[]) { | |
int a,b; | |
cin>>a>>b; | |
int c = a^b; | |
int count=0; | |
while (c) { | |
c = c&(c-1); | |
count++; | |
} | |
cout<<count; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment