Algorithm for bitwise fiddling

Posted by EquinoX on Stack Overflow See other posts from Stack Overflow or by EquinoX
Published on 2010-03-05T05:52:30Z Indexed on 2010/05/02 13:57 UTC
Read the original article Hit count: 285

If I have a 32-bit binary number and I want to replace the lower 16-bit of the binary number with a 16-bit number that I have and keep the upper 16-bit of that number to produce a new binary number.. how can I do this using simple bitwise operator?

For example the 32-bit binary number is:

1010 0000 1011 1111 0100 1000 1010 1001

and the lower 16-bit I have is:

                    0000 0000 0000 0001

so the result is:

1010 0000 1011 1111 0000 0000 0000 0001

how can I do this?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about bitwise-operators