+ 3
XOR is just like opposite of OR or something else ?
anyone can explain it.....
18 Respuestas
+ 4
It's quite different operator.
1 xor 0=1
1 xor 1=0
When both side is the same the result will be 0 or false and when they are different the result will be 1 or true
+ 9
Expression by Coder Kitten
a ^ b = (~a & b) | (a & ~b)
1010 -> 10
0101 -> 5
--------
1111 -> 15
https://www.sololearn.com/learn/4074/?ref=app
+ 7
I assume most of you have heard the real world examples, but if not: When you get asked "Do you want chocolate or vanilla ice cream", this is actually an exclusive or question, and "chocolate and vanilla" is probably not an option. Choices in meatspeak are usually xor.
+ 7
Ipang I have picked the worst example haha. :D
Also I think you want ~ instead of ! there, ! is logical not and ~ is bitwise :)
+ 5
Avinesh
How is XOR similar to !(a & b)?
+ 5
+ 4
This should be the expression-
(~a & b) | (a & ~b)
+ 3
See from link... It contains Or and Xor both..
In or, If any one is true, result is true
In xor, only any one is true, result is true otherwise false( should not both same)
https://www.sololearn.com/learn/4073/?ref=app
Edit:
https://www.sololearn.com/learn/4074/?ref=app
+ 3
Ipang you don't have to take the literal meaning of it and try executing the same. It was just used for the sole purpose of explaining the operators behaviour.
+ 3
Coder Kitten I could see the error that went unnoticed by me. I would replace it with your answer. Ipang thanks for commenting or else I would have never known that I committed a mistake and I would agree to it.
+ 3
Schindlabua
I think, "chocolate and vanilla" is also an option. I know I wouldn't mind to have both flavours *jk* 😁
+ 3
Ipang thanks for the noise I would say, I would have overlooked it if you and others wouldn't have commented.
+ 2
Unfortunately I have failed to understand how a XOR b be similar to !(a & b). This far I understand the same result (of XOR and !(a & b)) only comes when <a> and <b> are the same. Pardon my lacking of math skills, but I'm totally failing to understand here ...
(Edit)
As a matter of fact, I think I had successfully mess my undergrowth brain out 😂
+ 2
With all due respect, this snippet says differently. Is bitwise operation in Python different to that in C? please advise ...
#include <stdio.h>
int main()
{
int a = 10, b = 5;
printf("%d\n", (a ^ b));
printf("%d\n", ((!(a) & b) | (a & !(b))));
}
+ 2
XOR is Exclusive Or
It works the same as regular OR except it will return False if both conditions are True
You can acomplish x xor y in Python as:
(x or y) and not (x and y)
+ 2
NOR is the opposite of OR but XOR is different.
Go through this below code. So that you may understand...
https://code.sololearn.com/cYFPemHozket/?ref=app
+ 1
very interesting question
+ 1
Xor, exclusive or, ensures that one and only one of its args is true.
It is however replicable :
if((a && !b) || (b && !a)).
So when to use it? Well, only when it is absolutely necessary. The reason is that xor is not short circuited i.e. all expressions will be evaluated, unlike other logical operators. This might affect performance.
Not to say never use xor though. Here is a common usage for xor:
Say we have 2 files
A = 01101110
B = 10011101
And we want to store a backup on the cloud; one way is to save a copy of each; but what is really good, if we can store just one containing both data:
Backup = A XOR B;
Then to retrive A:
copy_of_A = Backup XOR B;