[<<][c][>>][..]
Sun Oct 30 15:00:38 EDT 2011

CPP macro for counting the number of bits in a word.

I don't know a way to write recursive macros; don't know how to
terminate the recursion and I don't know if recursion is supported in
the first place.  Though this is a simple manual unrolling:

#define NB_BITS_32(x) (NB_BITS_16(x) + NB_BITS_16(x >> 16)
#define NB_BITS_16(x) (NB_BITS_8(x) +  NB_BITS_8(x >> 8)
#define NB_BITS_8(x)  (NB_BITS_4(x) +  NB_BITS_4(x >> 4)
#define NB_BITS_4(x)  (NB_BITS_2(x) +  NB_BITS_2(x >> 2)
#define NB_BITS_2(x)  (NB_BITS_1(x) +  NB_BITS_1(x >> 1)
#define NB_BUTS_1(x)  (x & 1)
           



[Reply][About]
[<<][c][>>][..]