fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. unsigned count(unsigned n) {
  5. n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
  6. n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
  7. n = (n & 0x0F0F0F0F) + ((n >> 4) & 0x0F0F0F0F);
  8. n = (n & 0x00FF00FF) + ((n >> 8) & 0x00FF00FF);
  9. return (n & 0x0000FFFF) + ((n >> 16) & 0x0000FFFF);
  10. }
  11.  
  12. int main() {
  13. std::cout << count(65535);
  14. return 0;
  15. }
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
16