读了codeproject上的这篇《An introduction to bitwise operators,前面两个运算符说得不错,但第三个异或运算符感觉不够准确,作者给出的示例不知道有什么用处,不就是把数做了两次异或又回来了么?

 

&运算符用来判定某些位是0还是1
An introduction to bitwise operators#include <iostream>
An introduction to bitwise operators
using namespace std;
An introduction to bitwise operators
int main(void)
}

|运算符用来对某些位置1

An introduction to bitwise operators#include <iostream>
An introduction to bitwise operators
using namespace std;
An introduction to bitwise operators
int main(void)

异或运算符最常用的应该是用其实现两个数的交换:

An introduction to bitwise operators#include <iostream>
An introduction to bitwise operators
using namespace std;
An introduction to bitwise operators
int main(void)

   
   将取反运算符和与运算符结合起来,可以对某些位置零:

An introduction to bitwise operators#include <iostream>
An introduction to bitwise operators
using namespace std;
An introduction to bitwise operators
int main(void)

最后的位域有一个问题没搞懂:

An introduction to bitwise operators#include <iostream>
An introduction to bitwise operators
using namespace std;
An introduction to bitwise operators
An introduction to bitwise operators
struct date_struct 

我已经设置daymonth各自占据4位,应该是可以满足的,可结果却都是-8why?

相关文章: