Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » XOR Operator
- GeonoTRON2000
-
100+ posts
XOR Operator
I was wondering if there was any way to implement the xor operator (number 1 XOR number 2 and return a number.) Complicated is fine, credit will be given if it is possible to do this.
- Paddle2See
-
1000+ posts
XOR Operator
According to this website
http://cpsc.ualr.edu/srini/DM/chapters/examples/ex1.1.4.html
A logically equivalent to p XOR q
is
(p OR q) AND ( NOT ( p AND q ))
http://cpsc.ualr.edu/srini/DM/chapters/examples/ex1.1.4.html
A logically equivalent to p XOR q
is
(p OR q) AND ( NOT ( p AND q ))
- GeonoTRON2000
-
100+ posts
XOR Operator
I mean with integers such that: According to this website
http://cpsc.ualr.edu/srini/DM/chapters/examples/ex1.1.4.html
A logically equivalent to p XOR q
is
(p OR q) AND ( NOT ( p AND q ))
1) The integers are converted to bytes.
2) The first, second, third, etc bytes of the integers are xored (0 or 1 results) to get the result bytes
3) The result bytes are converted back to an integer
- MoreGamesNow
-
100+ posts
XOR Operator
I mean with integers such that: According to this website
http://cpsc.ualr.edu/srini/DM/chapters/examples/ex1.1.4.html
A logically equivalent to p XOR q
is
(p OR q) AND ( NOT ( p AND q ))
1) The integers are converted to bytes.
2) The first, second, third, etc bytes of the integers are xored (0 or 1 results) to get the result bytes
3) The result bytes are converted back to an integer
What do you mean? Do you want to convert a number from decimal to binary?
- MoreGamesNow
-
100+ posts
XOR Operator
<<(a) or (b)> and <not <(b) or (a)>>>
I think that will always return false.
If x = (a) or (b), then the above expression is equal to (x) and (not x), right?
- MoreGamesNow
-
100+ posts
XOR Operator
So yes, I just posted three times in a row, but I found an alternative that isn't completely awful 
a(+)b = !((a*b)+(!(a+b)))
xor = not (( & ) or (not( or )))

a(+)b = !((a*b)+(!(a+b)))
xor = not (( & ) or (not( or )))
- ScratchReallyROCKS
-
31 posts
XOR Operator
Yeah, I think they meant: <<(a) or (b)> and <not <(a) and (b)>>>
<<(a) or (b)> and <not <(b) or (a)>>>
I think that will always return false.
If x = (a) or (b), then the above expression is equal to (x) and (not x), right?
- Hardmath123
-
1000+ posts
XOR Operator
Guys? <not <<a> = <b>>>
Basically, XOR is true when the inputs are not equal, so a simple, elegant way is above.

- ScratchReallyROCKS
-
31 posts
XOR Operator
If only that carried over to other programming languagesGuys? <not <<a> = <b>>>
Basically, XOR is true when the inputs are not equal, so a simple, elegant way is above.

- MoreGamesNow
-
100+ posts
XOR Operator
Guys? <not <<a> = <b>>>
Basically, XOR is true when the inputs are not equal, so a simple, elegant way is above.
While that may be true, I prefer logic gate equivalents

- MoreGamesNow
-
100+ posts
XOR Operator
So, I was looking back at this and, while this may not still be pertinent to the topic (if it ever was), I just thought I'd let you guys know that my example is really just a derivative of Paddle2See's. I just realized that, since “and = not((not a) or (not b))”, mine can really be simplified to Paddle2See's solution… you know, if any of you really care that much xD So yes, I just posted three times in a row, but I found an alternative that isn't completely awful
a(+)b = !((a*b)+(!(a+b)))
xor = not (( & ) or (not( or )))
Last edited by MoreGamesNow (Feb. 4, 2013 22:54:06)
- technoguyx
-
500+ posts
XOR Operator
Guys, what the OP wants is to convert two base 10 integers to base 2, and then XOR their digits. i.e. 13 XOR 8 = 1101 XOR 1000 = 0101 = 5.
First, you'll have to convert the integers from decimal to binary, then iterate through every single digit in them, XORing them similarly to how Hardmath123 explained, in the first reply (return “1” only if both digits in a given position of the binary numbers, aren't equal). Return the result of this XOR operation, and then convert back to decimal if desired.
First, you'll have to convert the integers from decimal to binary, then iterate through every single digit in them, XORing them similarly to how Hardmath123 explained, in the first reply (return “1” only if both digits in a given position of the binary numbers, aren't equal). Return the result of this XOR operation, and then convert back to decimal if desired.
- GeonoTRON2000
-
100+ posts
XOR Operator
Thank you. Guys, what the OP wants is to convert two base 10 integers to base 2, and then XOR their digits. i.e. 13 XOR 8 = 1101 XOR 1000 = 0101 = 5.
First, you'll have to convert the integers from decimal to binary, then iterate through every single digit in them, XORing them similarly to how Hardmath123 explained, in the first reply (return “1” only if both digits in a given position of the binary numbers, aren't equal). Return the result of this XOR operation, and then convert back to decimal if desired.
- roijac_test
-
2 posts
XOR Operator
http://beta.scratch.mit.edu/projects/10044691/
Works directly without conversation.
Works directly without conversation.
Last edited by roijac_test (Feb. 11, 2013 17:04:29)
- MoreGamesNow
-
100+ posts
XOR Operator
http://beta.scratch.mit.edu/projects/10044691/
Works directly without conversation.
If I do xor(1)(1) with a length of 3 it returns 6. Shouldn't it return zero?
001
001
000
I then plugged in XOR(3)(1) and it returned four.
011
001
100
It seems to be operating more like a NAND gate than an XOR

- Discussion Forums
- » Help with Scripts
-
» XOR Operator