What exactly is that statement saying?Code:((var) &= ~(bit))
Is that saying toggle 0 or 1?
Or is that saying "whatever it equals
now it equals 0"?
Printable View
What exactly is that statement saying?Code:((var) &= ~(bit))
Is that saying toggle 0 or 1?
Or is that saying "whatever it equals
now it equals 0"?
What is var and what is bit?
The ~ operator flips all the bits. So if bit was set to, let's say, 6 (0110), ~bit would be 9 (1001), if bit was a 4-bit integer. Basically, it's a good way to set one or more bits to 0. In the example where bit is 6, you're turning off 2 bits:
val = 01011011 (hypothetically)
bit = 00000110
~bit = 11111001
01011011
& 11111001
---------------
01011001
To me it's saying:
OMG I must be a macro because I have far more brackets than necessary.
As for a description; It does the opposite of::devil:Code:((var) |= (bit))
thats why there so many brackets.
[/code]utils.h:186:#define REMOVE_BIT(var,bit) ((var) &= ~(bit))[/code]
ch->char_specials.saved.affected_by) ( 1 << 8)
but if
ch->char_specials.saved.affected_by doesnt equal (1<<8)
then functions that depend on 1<<8 wont be in affect.
lets say after
~(00001000)
what would that be?
hmm...Quote:
Originally Posted by errigour
Quote:
Originally Posted by itsme86
i meant to ask what that number would be after the ~ mark.
It depends on the size of the value you're flipping. If it's 32 bits in size, then you'd get more 0's turned into 1's, giving you a larger "number".
If you were dealing with 4-bit numbers then ~0x2 would be 1101 (13, 0xD), but if you're dealing with 8-bit numbers then ~0x2 would be 11111101 (253, 0xFD).
Is that what you're asking?
whould it flip this intiger
00000100 00000100
to this
00100000 00100000