diff options
author | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
---|---|---|
committer | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
commit | c24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch) | |
tree | 460a005b6a3a9a967bd881bc2bf01e0becbe33cc /2.9.c |
inital commit
Diffstat (limited to '2.9.c')
-rw-r--r-- | 2.9.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -0,0 +1,23 @@ +#include <stdio.h> + +int bitcount(unsigned num); + +int +main(void) +{ + int x = 1337; /* a random int */ + printf("%d\n", bitcount(x));; + + return 0; +} + +int +bitcount(unsigned num) +{ + int bits; + + for (bits = 0; num != 0; num &= (num-1)) + bits++; + + return bits; +} |