Skip to content

Instantly share code, notes, and snippets.

@atondwal
Created December 30, 2013 09:29
Show Gist options
  • Save atondwal/8179801 to your computer and use it in GitHub Desktop.
Save atondwal/8179801 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<cstdlib>
using namespace std;
int bits(int x){
if(!x) return x;
return (x&1)+bits(x>>1);
}
int main(int argc, char const* argv[])
{
int x = atoi(argv[1]);
cout << bits(x) <<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment