Skip to content

Instantly share code, notes, and snippets.

@7PintsOfCherryGarcia
Last active June 20, 2019 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7PintsOfCherryGarcia/6217ce58261083a7da69cc595a15e02e to your computer and use it in GitHub Desktop.
Save 7PintsOfCherryGarcia/6217ce58261083a7da69cc595a15e02e to your computer and use it in GitHub Desktop.
print number of set bits
/*
Copied from:
https://giannitedesco.github.io/2019/06/15/abusing-add.html
*/
#include <stdio.h>
int main() {
unsigned int number_bits;
unsigend int number = 255;
for(number_bits = 0; number; number &= (number - 1)) number_bits++;
printf("%d\n",number_bits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment