Use the following formula to determine class:
Assumptions: (not the same as database, making it up on the fly)
1 = Warrior
2 = Rogue
4 = Enchanter
8 = Wizard
16 = ...
32 = ....
(notice the binary increments?)
******************************************
Algorithm: (for the assumed classes, not all of them)
IF TEMP - 8 >= 0
UsableClass = "Wiz"
TEMP = TEMP - 8
ELSEIF TEMP - 4 >= 0
UsableClass = UsableClass & ", " & "Enc"
TEMP = TEMP - 4
ELSEIF TEMP - 2 >= 0
UsableClass = UsableClass & ", " & "Rog"
TEMP = TEMP - 2
ELSEIF TEMP - 1 >= 0
UsableClass = UsableClass & ", " & "War"
TEMP = TEMP - 1
************************************
Let's say the number in the database is 6 so we'll store it as TEMP. We also need a string to hold classes (for this example. You can store it anyway you choose)
So,
TEMP = 6
UsableClass = ""
In the first IF we'll have: 6 - 8 which is -2. This does not satisfy
the statement, so we know Wizard is NOT a usable class.
After Statement:
TEMP = 6
UsableClass = ""
In the second IF we'll have: 6 - 4 which is 2. This does satisfy
the statement, so we know Enchanter IS a usable class.
After Statement:
TEMP = 2
UsableClass = "Enc"
In the third IF we'll have: 2 - 2 which is 0. This does satisfy
the statement, so we know Rogue IS a usable class.
After Statement:
TEMP = 0
UsableClass = "Enc, Rog"
In the fourth IF we'll have: 0 - 1 which is -1. This does not satisfy
the statement, so we know Warrior is NOT a usable class.
After Statement:
TEMP = 0
UsableClass = "Enc, Rog"
(at this point, TEMP will be zero)
So, from this example, the number 6 represents the Enchanter and Rogue class. As you stated, the number 32767 is ALL classes because
1 + 2 + 4 + 8 + 16 + 32 +
64 + 128 + 256 + 512 +
1024 + 2048 + 4096 + 8192 + 16384
= 32767
SOooooo, each class's number is included in the TEMP (32767).
I hope this helps, it's really entertaining to work with such things.
|