Discuss Scratch

GeonoTRON2000
Scratcher
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.
Hardmath123
Scratcher
1000+ posts

XOR Operator

<not <<a> = <b>>>
Paddle2See
Scratch Team
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 ))
GeonoTRON2000
Scratcher
100+ posts

XOR Operator

Paddle2See wrote:

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 ))
I mean with integers such that:
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
PencilFactory
Scratcher
10 posts

XOR Operator


<<(a) or (b)> and <not <(b) or (a)>>>
MoreGamesNow
Scratcher
100+ posts

XOR Operator

GeonoTRON2000 wrote:

Paddle2See wrote:

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 ))
I mean with integers such that:
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
Scratcher
100+ posts

XOR Operator

PencilFactory wrote:


<<(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
Scratcher
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 )))
ScratchReallyROCKS
Scratcher
31 posts

XOR Operator

MoreGamesNow wrote:

PencilFactory wrote:


<<(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?
Yeah, I think they meant: <<(a) or (b)> and <not <(a) and (b)>>>
Hardmath123
Scratcher
1000+ posts

XOR Operator

Hardmath123 wrote:

<not <<a> = <b>>>
Guys?

Basically, XOR is true when the inputs are not equal, so a simple, elegant way is above.
ScratchReallyROCKS
Scratcher
31 posts

XOR Operator

Hardmath123 wrote:

Hardmath123 wrote:

<not <<a> = <b>>>
Guys?

Basically, XOR is true when the inputs are not equal, so a simple, elegant way is above.
If only that carried over to other programming languages
Hardmath123
Scratcher
1000+ posts

XOR Operator

not (str(a)==str(b))
a != b
That's all I care about.
MoreGamesNow
Scratcher
100+ posts

XOR Operator

Hardmath123 wrote:

Hardmath123 wrote:

<not <<a> = <b>>>
Guys?

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 . Try doing Boolean algebra on an “equal” gate! But you are correct, within the scope of this discussion yours is the best solution.
MoreGamesNow
Scratcher
100+ posts

XOR Operator

MoreGamesNow wrote:

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 )))
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

Last edited by MoreGamesNow (Feb. 4, 2013 22:54:06)

technoguyx
Scratcher
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.
GeonoTRON2000
Scratcher
100+ posts

XOR Operator

technoguyx wrote:

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.
Thank you.
roijac_test
Scratcher
2 posts

XOR Operator

http://beta.scratch.mit.edu/projects/10044691/
Works directly without conversation.

Last edited by roijac_test (Feb. 11, 2013 17:04:29)

MoreGamesNow
Scratcher
100+ posts

XOR Operator

roijac_test wrote:

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
roijac_test
Scratcher
2 posts

XOR Operator

you're right, of course
fixed
SuperJedi224
Scratcher
100+ posts

XOR Operator

a xor b= (a or b) and not(a and b)

Powered by DjangoBB