ID:2191698
Dec 25 2016, 7:33 pm
|
|
I don't know what this does, at all. I'm looking at code that uses it, and reading its helpfile doesn't really tell me much more. Could someone explain the particulars of its common use and less common uses to me? Thanks in advance.
|
In response to Gooobai
|
|
Gooobai wrote:
So states = 1 if you |= 1 it? 0 = 0b0000 1 = 0b0001 4 = 0b0100 So... 0000 | 0001 | 0100 = 0101 so yes, 5 a =| b is shorthand for a = a | b In terms of bits and binary operations, "|" is the bitwise OR operator, meaning when you OR two values, the returned value is a set of values from either. This means that if a = 0b0101 (5) and b = 0b1001 (9) then a | b = 0b1101 (13). 0101 | 1001 = 1101 |
Right, if you'll notice in his example above that he's doubling the value of the flag each time, the numbers between those values are used to determine which flags are enabled or disabled.
if(states&STATE_RUNNING) // If they're running |
You can also use it with list adding to ensure only a single entry exists for the item: