Text tools

Hamming distance

Hamming distance between a file and a second text you paste in. Runs entirely on your device.

Runs on your device. The file is never uploaded.

Hamming distance counts the positions where your file and the text pasted into compareTo hold different characters, and prints how many positions were read. It walks straight across from the start by UTF-16 unit, with no alignment and no case folding. Unequal lengths mean only the shorter overlap is read, under a note naming both.

Input

Options

Questions

What does it count?

The number of positions where the two texts hold different characters, compared straight across from the start. There is no alignment and no allowance for insertion or deletion, so the result answers how many substitutions separate two strings of the same shape. The output gives the distance and how many positions were compared.

What if the two inputs are different lengths?

It compares the overlap and tells you. Strict Hamming distance is only defined for equal lengths; rather than refuse, this tool compares the first N positions where N is the shorter length, then adds a note reading "inputs differ in length" with both lengths and how many positions were compared. Take that note seriously, because the trailing characters were not looked at.

How do I supply the second string?

Through the compareTo option. The tool takes exactly one file, which is the first side, and the text you type into compareTo is the second. That fits its usual jobs, checking a hash or a fixed-width code against a reference value, which are short enough to paste.

Can I use it on binary data or a hash?

On a hash written as text, yes, and that is a common use. The file is decoded as UTF-8 text before comparing, so raw binary is not a good input: invalid byte sequences become replacement characters and the comparison then runs on those. Compare hex or base64 representations rather than the raw bytes.

Is the comparison case-sensitive?

Yes, and there is no option to change that. Characters are compared exactly, so an upper-case and a lower-case letter in the same position count as a difference. Lower-case both sides with the Case converter first if that is not what you want. Comparison is by UTF-16 unit, so a character outside the Basic Multilingual Plane occupies two positions.

Related Text tools