Hello.
In the following code, which can be found in this tutorial, what does the operator ^= mean?
Thanks in advance.Code:#define SWAP(a, b) a ^= b; b ^= a; a ^= b;
Hello.
In the following code, which can be found in this tutorial, what does the operator ^= mean?
Thanks in advance.Code:#define SWAP(a, b) a ^= b; b ^= a; a ^= b;
^ is the symbol for the logical operator XOR (exclusive OR)
a ^= b is the same as a = a ^ b
Thanks. Appreciate it.
So it means
a equals exclusively a or exclusively b
Interesting...
So why then does it repeat the same thing two times, basically stating
a equals exclusively a or exclusively b
b equals exclusively a or exclusively b
(and then it says it again)
a equals exclusively a or exclusively b
?
Last edited by Programmer_P; 05-10-2009 at 08:37 PM.
stupid question, what is an exclusive or?
I was going to say that there aren't any stupid questions, but to be honest, after spending years on a forum on computer security(Not this one), I have to say that there are.
Yours, however, isn't.
XOR is an operator(So to speak) that is part of the boolean logic system invented by George Boole.
You should really look it up, as it's a much too complex subject for me to explain in a forum post, but let it suffice to say that the above code, due to the nature of the XOR operator, swaps the values. Also, boolean logic is pretty much the base of all circuitry ever made. Your computer is based on this stuff.
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
Sadly there are stupid questions, I work in customer service and deal with them on a daily basis. I think that there people who simply should not be allowed to have computers. I had to try and explain to a woman that if her computer was displaying another language that had to do with the settings on her computer and it had nothing to do with her monitor.
But all that aside
So I did google it, which is what I probably should have done in the first place, and all I can say is what a neat function! I'm a complete noob slowly working my way through my first C++ class. I've just mastered the += function and the basic concept of switches.
I thought I would start haunting programming boards to see what I can learn. I always seem to do better when I get in way over my head and am forced to sink or swim.
Same here. For some strange reason, I tend to learn more when asking a question on a forum, and get an answer, and go through each problem like that (if necessary; I do my best to learn the "normal" way), so its broken down, instead of learning by reading pages on a subject that is way over my head, though I always try to do that (and end up coming to the support forums, anyway, when I get stuck). I guess though if I didn't make an effort to read up first on the subject I'm trying to learn, I wouldn't even have any questions to ask, and so it at least serves as a motivator when I read up on the subject first. My brain seems to be geared to ask, and receive, type of learning. But, I eventually learn (by one method or another), and come back to the same board that helped me, to help other users that may be in the same boat I was.
Last edited by Programmer_P; 05-10-2009 at 09:09 PM.