Hi, Eärendil brought me here. The
thing is very misleading. This is processed by the Python-based compiler when generating the weird lines that end up in the
files and it only works at all because the bits of both numbers don't touch.
>>> hex(0x80000000 | 417)
>>> hex(0x80000000 ^ 417)
The game sees the same M&B operation code / opcode. So what? Why? ¯\_(ツ)_/¯
An exclusive OR (XOR) works like a plain OR whenever both bits are not one, see the truth table here and compare XOR with OR
. So using this for flags is a bit like falling sideways while going down a rail but sticking the landing;
technically produces the same result, but when you want to combine flags in a bitfield with the rest of a number you really
want to use the
operation to merge all the 1 bits from top and bottom into the same number, you don't really want that your bits return zero whenever the top and bottom bits are one, even if in this case does not happen, so you don't get this unintentional behavior with these particular module system numbers.
And I don't want to sound mean, but don't think the precision argument has any merit in this case because you are not shifting/rotating bits left or right, they stay in place, and they are of the same type/size. Sounds a bit like programming snake oil.
10000000000000000000000000000000 # 0x80000000 => 2147483648 in decimal => neg
110100001 # 0x1a1 => 417 in decimal => multiplayer_is_server
-------------------------------- # ----------
10000000000000000000000110100001 # 0x800001a1 = (0x80000000 | 0x1a1) which is the same as doing (0x80000000 | 417)
In the table above, if you do an OR operation, as long as there is some
in the input (e.g.
) it will output one
, for XOR if both are one (
) will be zero
, this is generally used to negate or toggle boolean variables easily. Turning
and vice versa.
: Don't get me wrong, XOR is very useful for many other low-level and fun operations, but it shouldn't be used for concatenating flags. I can use other unrelated operations that also give the same result and look cool, but that doesn't make it right.
>>> hex(0x80000000 + 417)
>>> hex((0x80000000 - ~417) - 1)
>>> hex(~(~0x80000000 & ~417)) # swy: same as OR, but obfuscated with NAND
Hope that helps at least a bit.