So what we'll do is use all the bits in a regular integer to hold these true / false values. Cog's integers have are 4 bytes long - that's 32 bits and boolean values we can store with one number.
Cog programmers commonly refer to a number used for boolean values as a flag. Flags aren't restricted to any base (e.g., decimal, hex), they're just integer numbers.
Before we get to hex, go to the Flags Section of the DM, and look at a few pages. The numbers are given in hex, but the point is that each line in the table is a true or false value that requires one bit to be turned on or off in the flag that we use.
The reason hex is easily converted to binary is that each digit in hex can display any combination of four digits in binary. This is because binary displays 2 values per digit while hex can display 16 (notice that I have to use decimal to write these numbers).
Here's a chart I'm borrowing from the bases tutorial:
Decimal | Binary | Hexadecimal |
---|---|---|
0 | 0 | 0 |
1 | 1 | 1 |
2 | 10 | 2 |
3 | 11 | 3 |
4 | 100 | 4 |
5 | 101 | 5 |
6 | 110 | 6 |
7 | 111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
You can see that hex uses letters after it runs out of numerals to use. Look at 1, 2, 4, and 8 in that table. Notice that each number uses only one bit. This means that we can add any combination of these numbers, and no matter what it is, we can disassemble it back to what we added up. E.g., 1 and 8 make 9. You can only subtract each of our key numbers once, so: 9 - 1 = 8. C - 4 = 8. Try it on your own.
Although we can write flags in decimal, bits don't evenly fit into decimal's digits, so doing simple addition gets complicated. Let's say we have the flag 0x80F. The 0x at the beginning means that the number is being displayed in hex. This is important because if you type a hex number without it, JK won't know it's in hex and will mistake it for decimal or a variable name.
But back to 0x80F. An F means that the first digit has all four bits on - these would be listed as 0x1, 0x2, 0x4, and 0x8 in the Flags Section of the DM. The third digit only has the the last bit turned on, and it's 0x800 by itself.
These flags can be assigned with the verb SetThingFlags() and cleared with the verb ClearThingFlags(). SetThingFlags() doesn't reset the flag, it just adds to it. You must use ClearThingFlags() to turn off bits in the flag. If you need to retrieve the value of a flag, you'd use GetThingFlags().
And that's pretty much it for this tutorial. You don't have to know that much about bases to be great with flags. If you want to learn more though, read the bases tutorial.