BITCOUNT macro in C -


how can count how many 0 bits in variable? must use macro thist bitcount(x,c) x variable , c count of 0 bits in x

example: x = 00101001 , c = 5

a simple solution:

#include <limits.h>

#define bitcount(x,c) \     { \         int i; \         (c) = 0; \         ( = 0; < char_bit * sizeof(x); i++ ) \             (c) += ( (x) & ( 1 << ) ) == 0; \     } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -