Reputation: 4117
Is there in C/C++ standart constant that reflects how many bits are there in one byte (8)? Something like CHAR_BIT but for byte.
Upvotes: 5
Views: 4637
Reputation: 624
The sizeof()
operator is consistent with CHAR_BIT
constant defined in <climits>
header, see the Notes section: https://en.cppreference.com/w/cpp/language/sizeof
Depending on the computer architecture, a byte may consist of 8 or more bits, the exact number being recorded in CHAR_BIT.
Above documentation defines the byte and its bits count.
Also some implementations of std::bitset
use CHAR_BIT
to obtain bits per byte.
Upvotes: 1
Reputation: 17900
According to the C standard, a char
is one byte. Therefore CHAR_BIT
is the number of bits in a byte.
The C standard says that CHAR_BIT
is "number of bits for smallest object that is not a bit-field (byte)".
Upvotes: 11