−7 arithmetic-shifted right by 1 is −4, not −3. The shift floors, and flooring goes down. A logical right shift on the same value gives 124, because it brings in a zero where the sign bit was. Both are correct; they are answers to different questions.
Left is multiplication
A left shift by n multiplies by 2ⁿ. Shift left once and the value doubles; three times and it is eight times larger.
It is faster than a multiply on most hardware, which is why compilers turn multiplication by a power of two into a shift without being asked. Writing the shift yourself is rarely worth the loss of readability — the compiler has already done it.
Bits that leave the top are gone. In a fixed-width register that is silent overflow: no exception, no flag most languages check, just a wrong answer. This page reports when it happens.
Shifting by the register width or more is undefined behaviour in C, which means a compiler may assume it never happens and optimise around it. Different processors genuinely give different answers.
Why two right shifts
Two right shifts exist because there are two reasonable things to bring in at the top, and which one is right depends on whether the value is signed.
Logical right shift brings in zeros. Correct for an unsigned value: it is division by a power of two.
Arithmetic right shift copies the sign bit. Correct for a signed value: it keeps a negative number negative.
They agree on every positive number, so the difference is invisible until a negative arrives — the same way floor and truncation agree on positives. Shift −7 right by one and you get either −4 or 124, depending entirely on which shift you used.
Languages handle this differently. C picks based on the type. Java has two operators, >> and >>>, and makes you choose. JavaScript has both too, and its >>> is the reason a negative number can suddenly appear as four billion.
Flooring, not truncating
An arithmetic right shift is division by a power of two — but it floors, and integer division in most languages truncates.
−7 >> 1 is −4. −7 / 2 in C is −3. Same operands, different answers, and both are doing what they say.
So a shift is not a drop-in replacement for a divide when the value can be negative. Code that optimises x / 2 into x >> 1 is correct for unsigned values and quietly wrong for signed ones — which is why compilers emit a correction step rather than a bare shift.
It is the same distinction as on the Floor and Ceiling page, arriving in a different costume. The underlying question is always which way to go when the answer falls between two integers.
Rotations lose nothing
A rotation moves bits off one end and brings them back at the other. Nothing is discarded.
That makes it reversible: rotate left by n and then right by n and the original value returns, exactly. A shift cannot promise that, because a shift throws bits away.
Cryptography relies on it. Block ciphers and hash functions are built from operations that must be invertible or that must preserve every bit of entropy, and rotations qualify where shifts do not. SHA-256 and AES both use them.
Most processors have a rotate instruction, and most high-level languages do not expose it — so it is usually written as two shifts and an OR, which the compiler recognises and turns back into the single instruction.
Where it gets used
Packing and unpacking. Several small values in one word: shift to position, mask to extract. Colour values, flags, and hardware registers all work this way.
Fast arithmetic. Multiplying and dividing by powers of two, and building arbitrary multiplications from shifts and adds where a multiplier is expensive.
Hash functions. Shifts and rotations mix bits so that a small change in the input changes many bits of the output.
Networking. Building and decomposing addresses, and applying subnet masks.
Sources and methodology
Shift semantics are defined by the language and the architecture; these are the references.
Method. The register width and the input base are explicit inputs, because both change the answer and neither can be inferred. The arithmetic right shift is implemented as floor division by a power of two rather than as a bit operation on the magnitude, which is what makes −7 >> 1 come out as −4; the suite checks that against Math.floor on every 8-bit value at four shift amounts. Rotations are asserted to be reversible, since nothing may be lost. That engine is verified on every change against 90 hand-written assertions, including that an arithmetic right shift equals floor division on every one of 1,024 signed 8-bit cases, and that rotating left then right by the same amount always restores the value. The count and the per-case breakdown are published on the formula verification page.
Read the guide
The floor-versus-truncate distinction is not a binary matter — the Floor and Ceiling Calculator covers it in ordinary arithmetic.