c++ - 按位操作函数

标签 c++ c bit-manipulation bitwise-operators

<分区>

Possible Duplicate:
How do you set, clear and toggle a single bit in C?

我正在为即将到来的期末考试学习,我想验证学习指南中的一些问题。

一些上下文:

  • Set() 函数将字节中的一位设置为 1

  • Unset() 函数将字节中的某个位设置为 0

  • Flip() 函数将位“翻转”到与原来相反的位置

所以我们类的某个 child 主动回答了学习指南的问题,但我已经发现了一些错误,这些答案听起来很可疑。他是这样说的:

Which operation is used for the Set? the or operator |

Which operation is used for the Unset? Xor operator ^ Done twice

Which operation is used for the Flip? Xor operator ^

在我上面描述的函数中,这些是正确的按位运算符吗?

最佳答案

设置用途或

取消设置使用 And

翻转使用异或

这已经在这里回答了: How do you set, clear, and toggle a single bit?

关于c++ - 按位操作函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11884629/

相关文章:

c++ - 如何绘制跟踪对象时的运动?

c++ - 在 Win32 控制台应用程序中使用 ShutdownBlockRequestCreate

c - 交换 "C"中句子中的单词

c# - 如何将复选框双向绑定(bind)到标志枚举的单个位?

c++ - 定义变量时出现奇怪的错误

c++ - 运行 cmd 命令并将结果获取到字符串变量

c - C中的时间测量

c - 从你只有 HWND 的窗口接收消息?

c++ - 我如何在 C++ 中将 bitset 转换为 short?

java - 链表中的节点(int索引)