问题
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()
.
来源:https://stackoverflow.com/questions/26168753/how-should-i-store-and-compute-hamming-distance-between-binary-codes