Some time ago, I searched for graph data on the Internet and found the hash algorithm. The obtained hash value is saved as a string. In this form, it is called a hash fingerprint. The string is a hexadecimal number, which is the number of different digits in binary. The following test code:
// Test. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <iostream> using namespace STD; int lsh (string str1, string str2); int sub (char a, char B); int _ tmain (INT argc, _ tchar * argv []) {string str1 = "9e0f53"; string str2 = "0b672a"; cout <"str1 =" <str1.c _ STR () <Endl; cout <"str2 =" <str2.c _ STR () <Endl; int Dis = lsh (str1, str2 ); cout <"Dis =" <dis <Endl; int A; CIN> A; return 0;} int lsh (string str1, string str2) {// int L = sizeof (str1.c _ STR (); int L = str1.length (); cout <"L =" <L <Endl; int Dis = 0; For (INT I = 0; I <L; I ++) {DIS + = sub (str1 [I], str2 [I]);} return DIS;} unsigned char char2hex (char a) {unsigned char T (0); Switch (a) {Case 'A': t = 10; break; Case 'B ': T = 11; break; Case 'C': t = 12; break; Case 'D': t = 13; break; Case 'E': t = 14; break; case 'F': t = 15; break; default: t = A-'0'; break;} return t;} int sub (char a, char B) {unsigned char a1 = char2hex (a); unsigned char b1 = char2hex (B); unsigned char C1 = A1 ^ B1; cout <"a1 =" <(INT) a1 <Endl; cout <"b1 =" <(INT) B1 <Endl; // cout <"C1 =" <(INT) c1 <Endl; int T (0); unsigned char TEM (1); For (INT I = 0; I <8; I ++) {If (C1 & (TEM) T ++; TEM = TEM <1 ;}cout <"t =" <(INT) T <Endl; return t ;}
Running result:
String hash value's distance comparison