程序:
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&amp; m带面具:00000000
结果10101010
我理解十六进制&amp;它的结果..但....... o & m
== 0000 0000
所以bits(o & m | newBits)
结果应该是0000 0000
,而不是1010 1010
......
我错过了这个概念......
任何人都可以帮助我......
期待良好的回应
由于
答案 0 :(得分:6)
o & m = 0000 0000
和newBits = 1010 1010
。因此,如果您将它们(按位)设为OR,则结果为1010 1010
0|0=0, 0|1=1, 1|0=1, 1|1=1
。
0000 0000 OR WITH
1010 1010
-----------------
1010 1010
-----------------