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).
計算結果僅為一般資訊用途的估算值,並非專業建議——在仰賴重要結果之前,請務必自行獨立查證。 閱讀完整免責聲明.
快速解答

此計算機如何運作?

兩個等長二進制字串的漢明距離是位元不同的位置數,等於其 XOR 的 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。等價地,距離等於兩個值的按位 XOR 中設置位的數量(即 popcount),因為 XOR 恰好在輸入不一致的位置產生 1。總長度是比較的位元數,匹配位元數為長度減距離,不同位置使用從左起從 0 開始的索引列出。

兩個字串必須等長,否則比較無定義,不顯示結果。含有所選字母表以外字元的輸入將被拒絕。漢明距離是編碼理論中的核心度量:編碼的最小漢明距離決定了它能檢測和糾正多少位元錯誤。

常見問題

漢明距離是兩個等長字串不同位置的數量。對於二進制資料,它等於兩個值的 XOR 中 1 位元的個數。

漢明距離僅對等長字串有定義,因為它逐位置比較位元。對於不同長度的字串,應改用編輯距離(Levenshtein 距離)。

每個十六進制數字展開為 4 個二進制位元(例如 F 變為 1111),然後將所得的位元字串作為二進制進行比較。

也稱為

漢明距離
海明距離
位元差異
hamming distance
比較二進位
錯誤更正距離
xor距離
漢明碼距

APA

TG we-Calculate Editorial Team. (2026). 漢明距離計算器 [Online calculator]. TG we-Calculate. https://we-calculate.com/zh-tw/calculator/hamming-distance-calculator

Chicago

TG we-Calculate Editorial Team. "漢明距離計算器." TG we-Calculate. 2026. https://we-calculate.com/zh-tw/calculator/hamming-distance-calculator.

IEEE

TG we-Calculate Editorial Team, "漢明距離計算器," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/zh-tw/calculator/hamming-distance-calculator

BibTeX

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

這個計算機對您有幫助嗎?