Jakub Mitura
Jakub Mitura

Reputation: 83

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 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!! 

Upvotes: 1

Views: 35

Answers (1)

Mojtaba Valizadeh
Mojtaba Valizadeh

Reputation: 766

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

unsigned int z = x | y;

Upvotes: 3

Related Questions