Original Post
I'm saving enum values to bit stream, and I would like to use only such number of bits as really required.
In the above example, the last entry has value of 10, meaning I need at least 4 bits to write it (assuming only positive values). I can calculate this value in runtime via a function, but it would a bit nicer to have this value at compile time so I could do this:
where cbcMessage would be "constant" bit count value (in this case 4).
Any ideas?
enum EMessage {
mOne = 0,
mTwo,
mThree,
...
mTen,
//
mLast, // value 10
};
In the above example, the last entry has value of 10, meaning I need at least 4 bits to write it (assuming only positive values). I can calculate this value in runtime via a function, but it would a bit nicer to have this value at compile time so I could do this:
enum EMessage {
mOne = 0,
mTwo,
mThree,
...
mTen,
//
mLast, // value 10
cbcMessage = Func( mLast ),
};
where cbcMessage would be "constant" bit count value (in this case 4).
Any ideas?