Math calculator

Bit Shift Calculator

Two right shifts, and they are not the same.

Two right shifts, not one

They differ only for negatives, which is why both exist.

−7 shifted 1 at 8 bits

1111 1100

Read as signed that is −4, and as unsigned 252. Bits fell off the end and cannot be recovered.

Before  1111 1001
After   1111 1100

Before, signed

−7

two’s complement reading

After, signed

−4

sign preserved

Before, unsigned

249

the raw bit pattern

After, unsigned

252

the raw bit pattern

Bits lost

yes

not reversible

  • The two right shifts differ ONLY for negative numbers, and that difference is the reason both exist. A LOGICAL right shift brings in zeros, so a negative value becomes a large positive one. An ARITHMETIC right shift copies the sign bit, preserving the sign.
  • An arithmetic right shift is floor division by a power of two, not truncated division. −7 >> 1 is −4, not −3, because flooring goes down and truncation goes towards zero — the same split as on the Floor and Ceiling page.
  • Bits were shifted off the bottom, so this operation is not reversible: the discarded low bits cannot be recovered.

An arithmetic right shift floors rather than truncates, so it is not the same as integer division for negatives.

What this tool shows

A logical right shift brings in zeros; an arithmetic one copies the sign bit. They agree on every positive number and disagree on every negative one.

  • Left shift, and what it multiplies by
  • Logical and arithmetic right shifts
  • Why they differ for negative numbers
  • Rotations, which lose nothing
  • Which bits fall off the end
  • Why a shift is not integer division
Shift and rotate Two right shifts Loss reported Four widths

Set the width — it decides what falls off the end.

Updated 7 September 2026 · Works in any browser, no installation

−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.

At a glance

Formula shown
A left shift by n multiplies by 2ⁿ, modulo the register width. A logical right shift divides an unsigned value by 2ⁿ. An arithmetic right shift floors a signed value by 2ⁿ, which is not the same as truncating it.
Scenario support
Reading a packed hardware register; implementing a fast multiply or divide; understanding why a negative value became huge.
Educational estimate
Planning support from the values you enter — not professional advice.

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.

Related calculators

Where this goes next:

BitwiseAND, OR, XOR, NOT, NAND, NOR and XNOR with truth tables and the bits laid out — at 8, 16, 32 or 64 bits, because NOT genuinely depends on the width.
Twos ComplementTwo's and one's complement at 8 to 64 bits, with the signed range and its asymmetry — and why negating the minimum gives back the minimum.
Binary ArithmeticAdd, subtract, multiply and divide in binary, octal or hex — with the carry row shown, and what a processor actually does instead of subtracting.
Floor and CeilingFloor, ceiling and truncation side by side — because for negative numbers those are three different answers, and floor(−2.5) is −3 while truncating gives −2.
Floating PointThe exact decimal value a double actually stores, written out in full — which is why 0.1 + 0.2 does not equal 0.3 in almost every programming language.
ModuloAll three conventions at once, because −7 mod 3 is −1 in JavaScript and 2 in Python and a page that gives only one of those is wrong for half its readers.

More in Math, or browse all calculators.

Read the guide

The floor-versus-truncate distinction is not a binary matter — the Floor and Ceiling Calculator covers it in ordinary arithmetic.

Educational use disclaimer

This is an educational tool. Shift behaviour depends on the register width and on the signedness of the value, and both are explicit here.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the bit shift page separating the logical and arithmetic right shifts, since they agree on every positive number and disagree on every negative one — the same invisibility that makes the floor-versus-truncate split a bug rather than a mistake.
  2. Implements the arithmetic right shift as floor division by a power of two rather than as a bit operation on the magnitude, so −7 shifted right by one comes out as −4 and the suite checks it against Math.floor on all 256 signed values.
  3. Flags when bits fall off the end, which is silent overflow in a fixed-width register — and notes that rotations lose nothing and are therefore reversible.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.