• Advertisement
Sign in to follow this  

explain this line of code?

This topic is 4333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
You can also use '!' if you want to reverse a boolean's value.

For example,


bool bDummy = bool();

bDummy = !bDummy; //bDummy -> true
bDummy = !bDummy; //bDummy -> false


Share this post


Link to post
Share on other sites
That's not the same though. ^ is a bitwise operator. It only flips individual bits, not the entire boolean expression.

Share this post


Link to post
Share on other sites
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 '!'...

Share this post


Link to post
Share on other sites

A B A xor B
0 0 0
0 1 1
1 0 1
1 1 0

Being bitwise, it goes bit by bit, so you shouldn't try to compare it with a logical operator, such as !.

Share this post


Link to post
Share on other sites
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 '^'...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement