如何从另一个修改一个整数的位
How to modify bit of one integer from another
Given 32 bit unsigned integers x and y I would like to set bits of
x to 1 if in corresponding position of y there is 1 without modifying
other bits of y So for example if x is
1 0 0 0 0 1 等等
y 是
0 0 0 1 0 0 等
I would like a result that would be 1 0 0 1 0 1 I suppose it can be
achieved somehow with & operator but i can not figure exactly how in
performing way.
谢谢你的帮助!!
您可以为此使用按位运算“或”:
unsigned int z = x | y;
Given 32 bit unsigned integers x and y I would like to set bits of x to 1 if in corresponding position of y there is 1 without modifying other bits of y So for example if x is
1 0 0 0 0 1 等等
y 是
0 0 0 1 0 0 等
I would like a result that would be 1 0 0 1 0 1 I suppose it can be achieved somehow with & operator but i can not figure exactly how in performing way.
谢谢你的帮助!!
您可以为此使用按位运算“或”:
unsigned int z = x | y;