What is Hamming Distance?

Hamming distance is a metric for comparing two binary data strings of equal length. It measures the number of bit positions in which the two bits are different, providing a quantitative way to assess how "close" or "far apart" two binary sequences are.

The Hamming distance between two strings a and b is denoted as d(a,b). This distance metric is fundamental in computer networks for error detection and correction, as well as in coding theory for comparing equal-length data words.

How It Works

To calculate the Hamming distance between two binary strings, we perform an XOR operation on the strings and count the total number of 1s in the result. Each 1 in the XOR result indicates a position where the original strings differ.

Hamming Distance Calculation String A: 1 1 0 1 1 0 0 1 String B: 1 0 0 1 1 1 0 1 A ? B: 0 1 0 0 0 1 0 0 Differences: Position 2 and Position 6 Hamming Distance = 2

Example Calculation

Consider two 8-bit strings: 11011001 and 10011101.

11011001 ? 10011101 = 01000100

The XOR result 01000100 contains two 1s, so the Hamming distance d(11011001, 10011101) = 2.

Minimum Hamming Distance

In a set of strings of equal lengths, the minimum Hamming distance is the smallest Hamming distance between all possible pairs of strings in that set. This value is crucial for determining the error-detecting and error-correcting capabilities of a code.

Example with Multiple Strings

Given four 3-bit strings: 010, 011, 101, and 111:

010 ? 011 = 001, d(010, 011) = 1
010 ? 101 = 111, d(010, 101) = 3
010 ? 111 = 101, d(010, 111) = 2
011 ? 101 = 110, d(011, 101) = 2
011 ? 111 = 100, d(011, 111) = 1
101 ? 111 = 010, d(101, 111) = 1

The minimum Hamming distance dmin = 1.

Key Applications

  • Error Detection − A code can detect up to dmin - 1 errors.

  • Error Correction − A code can correct up to ?(dmin - 1)/2? errors.

  • Data Integrity − Used in checksums and parity bits for data validation.

Conclusion

Hamming distance provides a fundamental measure of difference between binary strings, enabling effective error detection and correction in digital communication systems. The minimum Hamming distance of a code determines its error-handling capabilities.

Updated on: 2026-03-16T23:36:12+05:30

79K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements