Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有两个数字 A 和 B。我需要找出需要更改多少位数才能将 A 转换为 B。
像:
A = 1101101 B = 1011011 ^^ ^^
在这里,我们需要改变 4 位来将 A 转换为 B
我怎样才能做到这一点?
你可以简单地这样做:
int need=__builtin_popcountll(A^B); cout<<need;
有一个简单的解决方案:
A = 1101101 B = 1011011 ^^ ^^ C = 0110110 (A ^ B) ^^ ^^ (count set bit)