Last active
June 20, 2019 13:46
-
-
Save 7PintsOfCherryGarcia/6217ce58261083a7da69cc595a15e02e to your computer and use it in GitHub Desktop.
print number of set bits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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