I should be able to store a value in a data structure that could go from 0 to 3.. so I need 2 bits. This data structure I will be great 2 ^ 16 locations. So, i want to have 2 ^ 16 * 2 (bits). In C + + do you use to have exactly 2 bits in memory?
Share
You need two bits per unit (not three), so you can pack four units into one byte, or 16 units into one 32-bit integer.
So you will need a
std::array<uint32_t, 4096>to accomodate 216 units of 2-bit values.You access the nth value as follows:
Alternatively, you could go with a bitfield:
And then make an
std::array<BF32, 4096>.