Right Shift Operation:
From: | To: |
The bitwise right shift operator (>>) shifts the bits of a number to the right and fills 0 on voids left as a result. The leftmost bits fall off. This operation is equivalent to dividing the number by 2^n (where n is the number of bits shifted).
The right shift operation can be represented as:
Where:
Example: 8 >> 1 = 4 (binary 1000 becomes 0100)
Details: Right shift operations are commonly used in:
Tips: Enter any integer number and the number of bits to shift right. The calculator will show the result of the bitwise operation.
Q1: What happens to the bits that are shifted out?
A: They are discarded. Right shift is not a rotation operation.
Q2: How does right shift differ from division?
A: For positive numbers, right shift by n bits is equivalent to integer division by 2^n. For negative numbers, behavior depends on the programming language.
Q3: What's the maximum number of bits I can shift?
A: In PHP, shifting by more than the bit width of an integer (typically 32 or 64) gives undefined results.
Q4: Does right shift work with floating-point numbers?
A: No, bitwise operations only work with integers. Floating-point numbers will be converted to integers first.
Q5: What's the difference between >> and >>> operators?
A: >> is arithmetic right shift (preserves sign), while >>> (in some languages) is logical right shift (always fills with 0s).