Advertisement
gur111

Cound Off Bits Macro

Jun 1st, 2019
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.24 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define CODD(x,c)\
  4. {   \
  5.     for(c=0; x>0; x=x>>2){\
  6.         c += x&1;\
  7.     }\
  8. }
  9.  
  10.  
  11. int main(){
  12.     int b = 111111, c; /* 1011 */
  13.     CODD(b,c);
  14.  
  15.     printf("%d\n",c);
  16.     return 0;
  17. }
  18.  
  19.  
  20.  
  21.  
  22. /*
  23. 32 16 8 4 2 1
  24.  1  1 * 1 * 1  == 53
  25. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement