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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
- 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()
.