程序:

typedef bitset<8> bits;
char original = 0xF0F0F0F0;
char Mask = 0xFFFF0000;
char newBits = 0x0000AAAA;

/*& operation with "0bit set 0" & "1bit give no change to original byte" */
cout<<"Original o: "<<bits(original)<<endl;
cout<<"NewBits: "<<bits(newBits)<<endl;
cout<<"Mask m: "<<bits(Mask)<<endl;
cout<<"o & m with Mask: "<<bits(original & Mask)<<endl;/*0 set original bit as 0 */


结果:


  原始o:11110000
  NewBits:10101010
  遮罩m:00000000
  带蒙版的o&m:00000000
  结果10101010


我了解十六进制及其结果..但是......... o & m == 0000 0000所以bits(o & m | newBits)结果应该是0000 0000,而不是1010 1010 ...

我想念的地方...

谁能帮我...

期待良好的回应

谢谢

最佳答案

o & m = 0000 0000newBits = 1010 1010。因此,如果您对它们进行“或”(按位),您将得到1010 10100|0=0, 0|1=1, 1|0=1, 1|1=1的结果。

0000 0000 OR WITH
1010 1010
-----------------
1010 1010
-----------------

10-08 08:19