Intermediate

汉明距离计算器

比较两个等长二进制或十六进制字符串,统计它们位不同的位置数。

Input format

Hex strings are expanded to 4 bits per digit
Hamming distance
2

Number of positions where the bits differ

Total bit length
7
Matching bits
5
Differing bits
2
Differing positions (0-indexed)
2, 4
00.91.82.63.54.45.36.17027Hamming distance: 0 = identical, length = completely different
Step by step
  1. 1

    Total bit positions

    7
  2. 2

    Matching positions

    7 − 2 = 5
  3. 3

    Hamming distance

    7 − 5 = 2
    Number of positions where the bits differ — equivalent to popcount(A XOR B).
结果仅为一般参考性的估算,并非专业建议——在依赖这些重要结果之前,请务必自行独立核实。 阅读完整免责声明.
快速解答

这个计算器是如何工作的?

两个等长二进制字符串的汉明距离是它们位不同的位置数,等于其异或结果的 popcount。本工具比较两个二进制或十六进制字符串,报告距离、总位长、匹配位数及不同位的精确位置。

公式
Hamming distance = popcount(A XOR B) = number of positions where A and B differ
How this is calculated

输入两个等长字符串。选择输入格式:二进制字符串只使用字符 0 和 1,而十六进制字符串首先展开为其 4 位二进制表示(每个十六进制数字恰好变为 4 位,因此 2 位十六进制值变为 8 位)。

计算器逐位比较两个结果位串。每个位不同的位置对汉明距离贡献 1。等价地,距离等于两个值按位异或结果中置位数(population count,即 popcount),因为异或在输入不一致的位置恰好产生 1。总长度是比较的位数,匹配位数等于长度减距离,不同位置以从左起的从零开始的索引列出。

两个字符串必须等长,否则比较无定义,不显示结果。含有所选字母表以外字符的输入将被拒绝。汉明距离是编码理论中的核心度量:码字的最小汉明距离决定了该码能检测和纠正的位错误数量。

常见问题

它是两个等长字符串在对应位置上不同的个数。对二进制数据,它等于两个值异或结果中 1 位的个数。

汉明距离仅对等长字符串有定义,因为它逐位比较。对不同长度的字符串,应改用编辑距离(Levenshtein 距离)。

每个十六进制数字展开为 4 个二进制位(例如 F 变为 1111),然后将所得位串作为二进制进行比较。

也称为

汉明距离
海明距离
比特差异
二进制差异
异或距离
汉明距离计算

APA

TG we-Calculate Editorial Team. (2026). 汉明距离计算器 [Online calculator]. TG we-Calculate. https://we-calculate.com/zh/calculator/hamming-distance-calculator

Chicago

TG we-Calculate Editorial Team. "汉明距离计算器." TG we-Calculate. 2026. https://we-calculate.com/zh/calculator/hamming-distance-calculator.

IEEE

TG we-Calculate Editorial Team, "汉明距离计算器," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/zh/calculator/hamming-distance-calculator

BibTeX

@misc{wecalculate_hamming_distance_calculator, title = {汉明距离计算器}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/zh/calculator/hamming-distance-calculator}}, year = {2026}, note = {TG we-Calculate} }

这个计算器对您有帮助吗?