我应该如何存储和计算二进制代码之间的汉明距离? [英] How should I store and compute Hamming distance between binary codes?

查看:161
本文介绍了我应该如何存储和计算二进制代码之间的汉明距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 如何有效存储二进制代码?对于某些固定的大小,比如32位,可以使用原始类型。但是如果我的二进制代码长得多呢?

  2. li>


解决方案


  1. 使用 std :: bitset c>< bitset> 标头,其中 N 是位数( not bytes)。 >
  2. 使用<$ c $计算两个二进制代码 a b 之间的汉明距离c>(a ^ b).count()。


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

这篇关于我应该如何存储和计算二进制代码之间的汉明距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆