Skip to content

Instantly share code, notes, and snippets.

@priyanshujain
Created October 15, 2016 14:00
Show Gist options
  • Save priyanshujain/0db0bc44a3abdeffb915e4cff6f46efb to your computer and use it in GitHub Desktop.
Save priyanshujain/0db0bc44a3abdeffb915e4cff6f46efb to your computer and use it in GitHub Desktop.
number of bits that are different between two numbers
#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