How should I store and compute Hamming distance be

2019-07-04 06:10发布

  1. 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?

  2. What is the fastest way to compute the Hamming distance between two binary codes?

1条回答
萌系小妹纸
2楼-- · 2019-07-04 06:50
  1. Use std::bitset<N>, defined in the <bitset> header, where N is the number of bits (not bytes).
  2. Compute the Hamming distance between two binary codes a and b using (a ^ b).count().
查看更多
登录 后发表回答