Arithmetic right shift
An arithmetic right shift moves all bits of a number to the right by a given amount. In signed binary contexts, the key idea is that the sign is preserved: the leftmost bit is extended as the number shifts. This makes the result behave like division by powers of 2 for many signed values.
How to do it
- Identify the shift amount. Determine how many positions the number moves right.
- Shift the bits. Each bit moves one place to the right for each shift.
- Extend the sign bit. If the number is treated as signed, fill the new leftmost positions with the original sign bit.
- Read the result. Convert the final bit pattern back to the requested form, and simplify if needed.
Check your work
- For a nonnegative value, the shift should match integer division by 2 for each position shifted.
- For a signed negative value, make sure the leftmost bits were filled with 1s, not 0s.
- If the exercise asks for an exact saved answer, compare the final bit pattern carefully, not just the decimal value.
Common mistake
Do not use a logical right shift rule here. The important feature of an arithmetic shift is sign extension.