# Thread: Range of an enumeration...

1. ## Range of an enumeration...

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"...

2. The values used for an enumeration are being stored in a signed variable ????

3. 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...

4. 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).