我应该如何存储和计算二进制代码之间的汉明距离? [英] How should I store and compute Hamming distance between binary codes?
本文介绍了我应该如何存储和计算二进制代码之间的汉明距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-
如何有效存储二进制代码?对于某些固定的大小,比如32位,可以使用原始类型。但是如果我的二进制代码长得多呢?
li>
解决方案
- 使用
std :: bitset
c>< bitset> 标头,其中N
是位数( not bytes)。 >
- 使用<$ c $计算两个二进制代码
a
和b
之间的汉明距离c>(a ^ b).count()。
How can I efficiently store binary codes? For certain fixed sizes, such as 32 bits, there are primitive types that can be used. But what if I my binary codes are much longer?
What is the fastest way to compute the Hamming distance between two binary codes?
解决方案
- Use
std::bitset<N>
, defined in the<bitset>
header, whereN
is the number of bits (not bytes). - Compute the Hamming distance between two binary codes
a
andb
using(a ^ b).count()
.
这篇关于我应该如何存储和计算二进制代码之间的汉明距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文