If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Back to some basic stuff (enum range).

Depends on the values of dark & light.
If dark = 0 & light = 1 then the values can be represented in one bit.
The range of an unsigned 1 bit number is 0 to 1

enum e2 { a = 3, b = 9 }; // range: 0:15

In binary 3 = 11 & 9 = 1001
You need a minimum of 4 bits to cover this range.
The range of an unsigned 4 bit number is 0000 to 1111 = 0 to 15

enum e3 { min = -10, max = 1000000 }; // range -1048576:1048575

In binary, 1000000 = 11110100001001000000, which needs 20 bits.
As the other number is negative and assuming we are using 2's complement to represent negative numbers,
we need 21 bits.
1000000 = 011110100001001000000
-10 = 111111111111111110110
The range of a 2's complement 21 bit number is -1048576 to 1048575