explain this line of code?
a nice easy one for you all today!
i dont see what purpose the following line of code has, if i'm reading it right it doesnt actually do anything?
toggle[key] ^= 1;
thanks
ah ok, so it reverses a boolean? that makes sense. i was reading it as "key = key to the power of one"
toggle[key] = 0011011 = 000001 ^ (xor)--------------------- = 001100
turn off..... bits
You can also use '!' if you want to reverse a boolean's value.
For example,
For example,
bool bDummy = bool();bDummy = !bDummy; //bDummy -> truebDummy = !bDummy; //bDummy -> false
That's not the same though. ^ is a bitwise operator. It only flips individual bits, not the entire boolean expression.
Quote:Original post by Spoonbender
That's not the same though. ^ is a bitwise operator. It only flips individual bits, not the entire boolean expression.
Yes, but I was just pointing out that if all he wanted to do was change a boolean's value, he could use '!'...
A B A xor B0 0 00 1 11 0 11 1 0
Being bitwise, it goes bit by bit, so you shouldn't try to compare it with a logical operator, such as !.
As I've stated above, I was just POINTING OUT that if he wanted to change a boolean's value, he could use '!', that's all... I wasn't comparing '!' with '^'...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement