M
Martin Wells
Anyone know a good compile-time constant to tell you how many bits are
needed to store a given value?
For instance:
CALC_BITS_NEEDED(0) == 1
CALC_BITS_NEEDED(1) == 1
CALC_BITS_NEEDED(2) == 2
CALC_BITS_NEEDED(3) == 2
CALC_BITS_NEEDED(4) == 3
CALC_BITS_NEEDED(7) == 3
CALC_BITS_NEEDED(8) == 4
I need it as a compile-time constant coz I'll be using as an array
size. I first though of trying IMAX_BITS but it only works on numbers
where all bits are 1.
Martin
needed to store a given value?
For instance:
CALC_BITS_NEEDED(0) == 1
CALC_BITS_NEEDED(1) == 1
CALC_BITS_NEEDED(2) == 2
CALC_BITS_NEEDED(3) == 2
CALC_BITS_NEEDED(4) == 3
CALC_BITS_NEEDED(7) == 3
CALC_BITS_NEEDED(8) == 4
I need it as a compile-time constant coz I'll be using as an array
size. I first though of trying IMAX_BITS but it only works on numbers
where all bits are 1.
Martin