整数和位数组之间的按位运算
假设我有一个由位、1 和 0 组成的 C++ 数组,我想将其与整数进行按位异或,并得到整数结果。最快的方法是什么?
Suppose I have a c++ array of bits, ones and zeros, and I want to have it bitwise XORed with an integer number, and get the result as an integer. What is the fastest way to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的意思是
std::bitset
并且假设它适合 unsigned long,则unsigned long result = your_bits.to_ulong() ^ your_int< /代码>;
Assuming that you mean a
std::bitset
and assuming that it would fit into an unsigned long, thenunsigned long result = your_bits.to_ulong() ^ your_int
;