Bit Shift Calculator

Left-shift and right-shift integers, with logical and arithmetic modes.

Ad placeholder (leaderboard)

A bit shift moves all the bits of a value left or right by a number of positions. Shifts are among the fastest CPU operations and underpin fast multiplication and division by powers of two, bit packing, and hash functions. This calculator supports all three common shift modes at fixed register widths.

How it works

Within a register of width bits (mask = (1 << width) - 1):

  1. Left shift (<<) — every bit moves toward the most significant end; zeros enter from the right and bits that fall off the top are discarded. This multiplies by 2^n modulo the width.
  2. Logical right shift (>>>) — bits move toward the least significant end; zeros enter from the left. This is unsigned division by 2^n.
  3. Arithmetic right shift (>>) — like the logical shift, but the sign bit is copied into the vacated high bits, preserving the sign of a two’s-complement value.

Example

Take the 8-bit value 0b00010110 (22):

  • Left shift by 2 → 0b01011000 = 88 (which is 22 × 4).
  • Logical right shift by 1 → 0b00001011 = 11.

Now take 0b10110110 interpreted as signed (−74). An arithmetic right shift by 1 gives 0b11011011 (−37), keeping the value negative, whereas a logical right shift would give 0b01011011 (91), changing the sign.

Notes

Choose the width to match your target type. Note that arithmetic right shift rounds toward negative infinity, so -1 >> 1 stays -1, unlike integer division which would round toward zero — a subtle but important difference when implementing signed math with shifts.

Ad placeholder (rectangle)