Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // Count amount of '1' bits
- int bitcount(unsigned int x)
- {
- int cnt ;
- for (cnt = 0; x != 0; x &= (x - 1))
- cnt++;
- return cnt;
- }
- int main(void)
- {
- int x, y;
- x = 2679;
- y = 1473;
- printf("bitcount for %i is %i\n", x, bitcount(x));
- printf("bitcount for %i is %i\n", y, bitcount(y));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement