ʞɔıu
ʞɔıu

Reputation: 48446

Why does this xor operation result in zero in mysql?

Why does this xor operation zero out?

mysql> select 17246357237183571361 xor 13175113390712773921;

+-----------------------------------------------+
| 17246357237183571361 xor 13175113390712773921 |
+-----------------------------------------------+
|                                             0 |
+-----------------------------------------------+

Upvotes: 2

Views: 524

Answers (2)

Kay
Kay

Reputation: 644

The answer of Captain Giraffe is correct but probably it's useful to know that you can write the following to have MySQL executing a bitwise XOR on the operands:

mysql> select 17246357237183571361 ^ 13175113390712773921;

The result would be 6449217728581286016.

I needed this to determine the hamming distance of 2 perceptual hashes (similar image search) which is easily done by this line

BIT_COUNT(pHash1 ^ pHash2)

Perhaps other users can profit from :-)

Upvotes: 3

Captain Giraffe
Captain Giraffe

Reputation: 14705

That is not a bitwise operation it is a logical operation. See http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html

So it boils down to 1 xor 1

Upvotes: 7

Related Questions