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 |
+-----------------------------------------------+
| 开发者_Python百科 0 |
+-----------------------------------------------+
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
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 :-)
精彩评论