C语言程序设计 - XOR位运算 [英] C Programming - XOR Bitwise Operation

查看:223
本文介绍了C语言程序设计 - XOR位运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下操作'C'语句执行什么操作?

What operation does the following ‘C’ statement perform?

明星= ^星0b00100100;

star = star ^ 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位运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆