## #75 – New Bits When Shifting

August 31, 2010 1 Comment

When doing bitwise shifting using the << and >> operators, the data value being shifted will always shift new bits in–from the left when right shifting, or from the right when left shifting. The value of the new bits depend on the direction of the shift and the data type being shifted.

- Right shift
- If shifting
**int**or**long**, new bits at left match sign of the value - If shifting
**uint**or**ulong**, new bits at left are 0-valued

- If shifting
- Left shift
- New bits at right are 0-valued

Shift operations can never result in an overflow.