Sign in to follow this  
judge dreadz

explain this line of code?

Recommended Posts

judge dreadz    193
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
raz0r    586
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
raz0r    586
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
Kalazart    148

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
raz0r    586
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this