fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int countsetbit(int t)
  5. {
  6. int res =0;
  7. while(t>0)
  8. {
  9. t = (t&(t-1));
  10. res ++;
  11. }
  12. return res;
  13. }
  14.  
  15. int bitdiff(int m,int n)
  16. {
  17. return countsetbit(m^n);
  18. }
  19.  
  20. int main() {
  21. int m=10;
  22. int n = 20;
  23. cout << bitdiff(m,n);
  24. return 0;
  25. }
Success #stdin #stdout 0s 5468KB
stdin
Standard input is empty
stdout
4