How should I store and compute Hamming distance between binary codes?

蓝咒 提交于 2019-12-14 01:46:33

问题


  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:


  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().


来源:https://stackoverflow.com/questions/26168753/how-should-i-store-and-compute-hamming-distance-between-binary-codes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!