I need an explination of this:
..." The range of an enumeration holds all the enumeration's enumerator values rounded up to the nearest larger binary power minus one"...
This is a discussion on Range of an enumeration... within the C++ Programming forums, part of the General Programming Boards category; I need an explination of this: ..." The range of an enumeration holds all the enumeration's enumerator values rounded up ...
I need an explination of this:
..." The range of an enumeration holds all the enumeration's enumerator values rounded up to the nearest larger binary power minus one"...
The values used for an enumeration are being stored in a signed variable ????
3 enumerations - largest binary power is 2 ^ 2 - 1 = 3
17 enumerations - largest binary power is 2 ^ 5 - 1 = 31
43 enumerations - largest binary power is 2 ^ 6 - 1 = 65
65000 enumerations - largest binary power is 2 ^ 16 - 1 = 65535
etc...
hasafraggin shizigishin oppashigger...
Hi,
Lets say you have the following:
enum { IDLE, STARTING, RUNNING, ENDING, INVALID };
the size of the enumeration MUST be big enough to contain highest value of the enumeration, in this case it must be 4 (since INVALID == 4), and it must be a value that is a power of 2, minus 1.
So for us to be able to store the value 4, the enumeration must be a power of 2 minus one that is bigger or equal to 4.. in this case that's 2^3 - 1 = 8 - 1 = 7. So this enumeration can store from 0-7 (not just the 0-4 that we need).
If you had:
enum { IDLE = 23, STARTING, RUNNING, ENDING, INVALID };
then the enumeration would need to hold a max value of 27, the nearest power of two minus one is 31... so the size of the enumeration would be 31.
hope that helps.
U.
Quidquid latine dictum sit, altum sonatur.
Whatever is said in Latin sounds profound.