|
Each flag is represented by a number 2^n (where n=1,2,3,...), so you have the flags 1, 2, 4, 8, 16, 32, 64 and so on. In hexadecimal (base 16), this is the same as 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100 et cetera. By simply adding these numbers together, you can represent any combination of flags as a single unique number. Any number can be represented by one and only one combination of flags like this. Let's take your flag as an example:
150994974 = 134217728 + 16777216 + 16 + 8 + 4 + 2 = 2^27 + 2^24 + 2^4 + 2^3 + 2^2 + 2^1
It's easier to see in hexadecimal notation:
150994974 = 0x0900001e = 0x08000000 + 0x01000000 + 0x00000010 + 0x00000008 + 0x00000004 + 0x00000002
And even easier to see in binary notation:
150994974 = 0x0900001e =
0000 1001 0000 0000 0000 0000 0001 1110 =
0000 1000 0000 0000 0000 0000 0000 0000 +
0000 0001 0000 0000 0000 0000 0000 0000 +
0000 0000 0000 0000 0000 0000 0001 0000 +
0000 0000 0000 0000 0000 0000 0000 1000 +
0000 0000 0000 0000 0000 0000 0000 0100 +
0000 0000 0000 0000 0000 0000 0000 0010
In binary notation, setting a flag is the same as turning one of the 32 zeroes above into a 1. So you see, there can be exactly 32 flags if the size of the variable is 32 bits (one bit is either 0 or 1), aka four bytes (one byte is 8 bits), like above.
Now look again at _defines.fos, at the item flags. You'll see for example that ITEM_CAN_PICKUP is 0x08000000, which is one of the flags in your number. You will also see that ITEM_CAN_USE is defined as 0x10000000, which is 2^28 = 268435456. So to set that flag, all you have to do is to add that number to your flag. |
|