如何在 C++ 中实现 AND 和 OR 运算
我有一个作业,我应该用 C++ 实现 MIPS 处理器,其中一条 MIPS 指令是“AND”和“OR”,MIPS 指令表示为 and $s1,$s2,$s3 这意味着
$s1=$s2(and)$s3
$s2 和 $s3
寄存器被表示为位,,, 我如何执行“AND”使用 C++ 进行“和”或“运算?
I have an assignment that I'm supposed to implement the MIPS processor in C++ and one of the MIPS instructions is "AND" and "OR" the MIPS instruction is represented as and $s1,$s2,$s3
which means that $s1=$s2(and)$s3
the $s2 and $s3
registers are represented into bits ,,, how can I perform the "AND" and "OR" operations using C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C++ 中既有二进制运算符,也有逻辑 and 和 or 运算符。
There are both binary and logical and and or operators in C++.
布尔比较将根据两个操作数的值返回 true 或 false。如果两个操作数都非零,逻辑“与”将返回 true。仅当两个操作数都为假时,逻辑“或”才会返回假。
位运算符则不同,它对操作数的位进行运算。仅当两个对应位都为 true 时,按位“and”才会将某个位设置为 true:
仅当两个相应位都为零时,按位“or”才会将某个位设置为零:
两个按位比较运算符与移位运算符关系更密切(<< 和 >>) 和补码运算符 (~),因为它们是低级运算。
A boolean comparison will return true or false depending on the value of the two operands. Logical "and" will return true if both operands are non-zero. Logical "or" will return false only if both operands are false.
Bitwise operators are different and operate on the bits of the operands. A bit wise "and" will set a bit to true only if both corresponding bits are true:
Bitwise "or" sets a bit to zero only if both corresponding bits are zero:
The two bitwise comparison operators are more closely related to the shift operators (<< and >>) and the one's complement operator (~) in that they are low level operations.