Let's say I have two integers with the following binary representations:
01101010
00110101
And now I want to copy the last 3 bits from the first integer over the second one so that it becomes
00110010
What's the easiest way to do that?
(Actually, my goal is to shift the all the X+1 bits to the right one, essentially deleting the Xth bit, and keeping the X-1 bits the same -- in this case, X is 4)
The "why?":
You have a bunch of flags,
1 = 'permission x'
2 = 'permission y'
4 = 'permission z'
8 = 'permission w'
You decide that that "permission y" is no longer needed in your program, and thus shift z and w up a position (making them 2 and 4 respectively). However, now you need to update all the values in your database.... (what formula do you use?)