I am trying to understand the difference of vocabulary used in the C++ language between digits and bits as in :
CHAR_BIT;
std::numeric_limits<char>::digits;
Is there a conceptual difference? Maybe for weird architectures?
If so, what would be called the result of the operator[]
of std::bitset
. Does it give access to a bit or to a digit?
And the current documentation of boost does not help: cppint provides a code with Digits
but the documentation mention Bits
(this is obviously a problem with the documentation, but I don't know whether the text or the code is more recent.)
From this
std::numeric_limits::digits
reference:And later it states that for
char
the result isCHAR_BIT - std::numeric_limits<char>::is_signed
.And from the C numeric limits reference:
So for a normal modern computer, where
char
is eight bits, thenCHAR_BITS
is equal to8
and thedigits
function will return either7
or8
depending on ifchar
is signed or not.I agree that the using the word "digits" is is kind of confusing when getting the number of bits in an integer type, but it makes much more sense for floating point types:
And
std::bitset
is a set of bits, so the indexing operator will give you the selected bit in the set.