comparehash

A bitwise XOR of two big Integers. Returns the difference in percent.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
    MYSQL QUERY
*/
SELECT ((64 - bit_count(hash1 ^ hash2))*100.0/64);
/*
    MYSQL Function
*/
DELIMITER $$
DROP FUNCTION IF EXISTS comparehash $$
CREATE FUNCTION comparehash (hash1 biginthash2 bigint)
RETURNS float
DETERMINISTIC
BEGIN
     RETURN ((64 - bit_count(hash1 ^ hash2))*100.0/64);
END $$
DELIMITER ;
X

Url: http://www.medienservice-ladewig.de/MYSQL-Hamming-Distance.2099932101.html

Language: SQL | User: Jörg | Created: Oct 21, 2013 | Tags: mysql bitwise xor function