Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CHAR_BIT replacement

CHAR_BIT defines the number of bits per character. But it is an old macro. Similar macros have been replaced in recent C++ standards.

Is there a more modern replacement for CHAR_BIT in C++11/14/17?

like image 969
Silicomancer Avatar asked Dec 19 '22 06:12

Silicomancer


1 Answers

The number of non-sign bits is provided by std::numeric_limits<T>::digits, so it can be determined by:

std::numeric_limits<unsigned char>::digits

Note the use of the unsigned qualifier to ensure there are no sign bits.

like image 148
Clifford Avatar answered Dec 24 '22 01:12

Clifford