What's the best data type that can handle a sequence of digits [0:9] in c++ with the least possible waste in memory?
I think it may be something like that
typedef bitset<4> Digit;
vector<Digit> myVector;
but I think that each bitset<4> reserves a byte -the same as a char-, so it's not better than a normal string, is it?
Are there any better idea to handle something like that?
To store a value from a set of 10, 4bits are required.
But on 4 bits, 16 values can be represented. That is a waste of 6/16 =37.5%.
So the best representation would minimize the amount of waste.
The best way is to store in binary, where all the combinations of bits are utilized.