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 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"?
Last edited by errigour; 11-09-2010 at 10:31 PM.
What is var and what is bit?
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
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
If you understand what you're doing, you're not learning anything.
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:Code:((var) |= (bit))
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
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?
Last edited by errigour; 11-10-2010 at 12:15 PM.
hmm...Originally Posted by errigour
Originally Posted by itsme86
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i meant to ask what that number would be after the ~ mark.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
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?
If you understand what you're doing, you're not learning anything.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
whould it flip this intiger
00000100 00000100
to this
00100000 00100000