整数和位数组之间的按位运算

发布于 2024-12-12 18:19:49 字数 64 浏览 3 评论 0原文

假设我有一个由位、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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦中楼上月下 2024-12-19 18:19:50

假设您的意思是 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, then unsigned long result = your_bits.to_ulong() ^ your_int;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文