Hamming Distance

Apr 4, 2012 at 2:37pm
Hi
Can anyone please help write a Hamming Distance function that compares two strings, then return the Hamming Distance between them.
Apr 4, 2012 at 2:50pm
just do an AND operator between the two binary numbers and then count the 1's..

shouldn't be too hard
Apr 4, 2012 at 2:56pm
AND will not work.
Apr 4, 2012 at 2:58pm
oops EXOR? :)
Apr 4, 2012 at 2:59pm
That doesn't work....actually I'm trying to develop a spellchecker application that make use of the Hamming distance.
Apr 4, 2012 at 3:00pm
It's easy. Just count the difference: http://en.wikipedia.org/wiki/Hamming_distance
Apr 4, 2012 at 7:58pm
I do understand the Hamming Distance but I need to create a function using c++
Apr 9, 2012 at 10:40pm
if you are comparing strings with the same length, you can use CompareTexts() - st1.Length, you will get a hamming distance, but i dont know about a proper way or the documented way, i just created that for myself.
Apr 10, 2012 at 12:43am
You'll need to use a loop, for n in [0, length_of_shortest_string - 1], and count the number of times the characters in the strings differ.
Topic archived. No new replies allowed.