问题描述
执行以下操作'C'语句执行什么操作?
What operation does the following ‘C’ statement perform?
明星= ^星0b00100100;
(A)切换位2和变星的5。
(A) Toggles bits 2 and 5 of the variable star.
(B)清除除2位和变星的5位全部
(B) Clears all bits except bits 2 and 5 of the variable star.
(C)设置除2位和变星的5位全部
(C) Sets all bits except bits 2 and 5 of the variable star.
(D)与0b00100100变星值相乘
(D) Multiplies value in the variable star with 0b00100100.
我仍然毫无头绪这一点。有人可以帮我吗?
I'm still clueless about this. Can someone help me out?
推荐答案
XOR运算符(也称为逻辑加法)的定义是这样的:
XOR operator (also called "logical addition") is defined like this:
a b a^b
-----------
0 0 0
0 1 1
1 0 1
1 1 0
所以 A ^ 0
叶 A
不变,同时 A ^ 1
切换了。
有关的多个位的值,则操作进行按位,即操作数的相应的位之间。
For multiple-bit values, the operation is performed bitwise, i.e. between corresponding bits of the operands.
这篇关于C语言程序设计 - XOR位运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!