Value x is a 32-bit unsigned integer 3:

00000000000000000000000000000011

If we use bitwise-shift to shift all bits to the right by 2, x is 0:

00000000000000000000000000000000

If we then do a bitwise leftshift on x by 30, do we end up with:

11000000000000000000000000000000

or

00000000000000000000000000000000

In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear?

00000000000000000000000000000011

If we use bitwise-shift to shift all bits to the right by 2, x is 0:

00000000000000000000000000000000

If we then do a bitwise leftshift on x by 30, do we end up with:

11000000000000000000000000000000

or

00000000000000000000000000000000

In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear?

You get

00000000000000000000000000000000

Note that 00000000000000000000000000000000 is equivalent to 0; and bit shifting any number by x to the left means`number * 2`^{x} and bit shifting any number by x to the right means `number / 2`^{x}. So in any case, bitshifting zero in any direction will always result in zero

00000000000000000000000000000000

Note that 00000000000000000000000000000000 is equivalent to 0; and bit shifting any number by x to the left means

Last edited on

In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear? |

No.

Topic archived. No new replies allowed.