XOR is just like opposite of OR or something else ? | Sololearn: Learn to code for FREE!
+ 3

# XOR is just like opposite of OR or something else ?

anyone can explain it.....

14th May 2020, 8:24 PM
𝒱𝑒𝓃𝑜𝓂𝑜𝓊𝓈
18 ответов
+ 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
15th May 2020, 11:08 AM
‎‏‪Milla
+ 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
14th May 2020, 8:28 PM
Avinesh
+ 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.
14th May 2020, 11:12 PM
Schindlabua
+ 7
Ipang I have picked the worst example haha. :D Also I think you want ~ instead of ! there, ! is logical not and ~ is bitwise :)
14th May 2020, 11:18 PM
Schindlabua
+ 5
Avinesh How is XOR similar to !(a & b)?
14th May 2020, 10:01 PM
Ipang
+ 5
Got it Avinesh , Coder Kitten and Schindlabua Big Thanks everyone Sorry for the noise 🙏
14th May 2020, 11:21 PM
Ipang
+ 4
This should be the expression- (~a & b) | (a & ~b)
14th May 2020, 11:18 PM
Avinesh
+ 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
14th May 2020, 8:27 PM
Jayakrishna 🇮🇳
+ 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.
14th May 2020, 10:06 PM
Avinesh
+ 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.
14th May 2020, 10:49 PM
Avinesh
+ 3
Schindlabua I think, "chocolate and vanilla" is also an option. I know I wouldn't mind to have both flavours *jk* 😁
14th May 2020, 11:15 PM
Ipang
+ 3
Ipang thanks for the noise I would say, I would have overlooked it if you and others wouldn't have commented.
14th May 2020, 11:22 PM
Avinesh
+ 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 😂
14th May 2020, 10:36 PM
Ipang
+ 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)))); }
14th May 2020, 11:09 PM
Ipang
+ 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)
16th May 2020, 7:36 AM
NourEddine Yassine
+ 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
16th May 2020, 1:23 PM
Jenson Y
+ 1
very interesting question
15th May 2020, 9:50 PM
Logomonic Learning
+ 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;
16th May 2020, 6:29 AM
Актуальное сегодня
HELP ME
Python
hearts
A long time