Home > front end >  How to modify bit of one integer from another
How to modify bit of one integer from another

Time:11-29

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 etc.

and y is 

0 0 0 1 0 0 etc.

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.

Thank you for help!! 

CodePudding user response:

You can use the bitwise operation "or" for this purpose:

unsigned int z = x | y;
  • Related