How do i create basic datatypes with custom bit widths?
Example: I need a 20 bit signed integer.
I am modeling hardware that can have custom bit widths. How do I do it
in C++?
There is a bitset<N> template in the standard library (actually it
doesn't belong to the standard library but is ditributed with the STL)
which can store number of bits specified by you. You might be interested
in that ... <bitset>
std::bitset<20> store_bits; // 20 bits to be stored in store_bits;
It also has many useful function helping to operate on single bits,
access to particular bits (operator[]), manipulate, inverse etc. return
as a unsigned int or std::string etc. Construct object by providing bits
as a std::string or unsigned number etc.
Regards.