The quantity of bits used by an unsigned integer type in memory can be
determined by:
typedef unsigned long long UIntType;
CHAR_BIT * sizeof(UIntType )
However, what would be a good portable way to determine how many of these
bits are value bits? If possible, it would be nice to have it as a
compile time constant.
Here's something I played around with:
typedef unsigned long long UIntType;
unsigned GetQuantityValu eBits(void)
{
/* We know it's atleast 8 in anyway */
unsigned quantity = 8;
UIntType val = 128;
while (val <<= 1) ++quantity;
return quantity;
}
Also, we could determine the amount of non-value bits (trapping bits
perhaps) from:
sizeof(UIntType ) * CHAR_BIT - GetQuantityValu eBits()
-Tomás
Comment