What does right shift (>>) do?

Prepare for the Computer Programming Test. Dive into a world of coding with multiple choice questions, flashcards, and detailed explanations. Boost your knowledge and be exam-ready!

Multiple Choice

What does right shift (>>) do?

Explanation:
Right shift moves bits to the right. Each bit is shifted one position toward the least-significant end, the rightmost bit is dropped, and the new leftmost bit is filled in. For unsigned values, the left fill is zeros, so the operation halves the number (roughly, discarding the remainder). For signed integers, many languages perform sign extension, filling the left with the original sign bit to preserve negativity. This is different from shifting left (which moves bits to the left and tends to double the value) and from flipping all bits. In short, the operator moves bits right, effectively dividing by two for non-negative numbers.

Right shift moves bits to the right. Each bit is shifted one position toward the least-significant end, the rightmost bit is dropped, and the new leftmost bit is filled in. For unsigned values, the left fill is zeros, so the operation halves the number (roughly, discarding the remainder). For signed integers, many languages perform sign extension, filling the left with the original sign bit to preserve negativity. This is different from shifting left (which moves bits to the left and tends to double the value) and from flipping all bits. In short, the operator moves bits right, effectively dividing by two for non-negative numbers.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy