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 -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -