Bit Shift Calculator

Logical and arithmetic shifts and rotations on 8–64-bit words.

What it does

Shifts or rotates the bits of a number left or right, with logical and arithmetic shifts and rotations on 8- to 64-bit words.

Where it's used

Fast multiply/divide by powers of two, packing bit fields, checksums and hashing.

How to use it

  1. Type the value (decimal, hex or binary).
  2. Choose the operation.
  3. Enter the shift amount and word size.

The formula explained

x ≪ k
x × 2ᵏ (bits falling off the top are lost)
x ≫ k
⌊x / 2ᵏ⌋, filling with 0 (logical)
Arithmetic ≫
fills with copies of the sign bit
Rotate
bits that fall off re-enter on the other side

Worked example

Rotating 0x81 right by one bit.

Inputs:

The calculator gives:

Tips and common mistakes

Questions people ask

Is a shift the same as multiplying or dividing?

Shifting left by n multiplies by 2^n, as long as no bits fall off the top. Arithmetic shifting right by n divides by 2^n, rounding down — so −5 ≫ 1 is −3, not −2.

What is the difference between logical and arithmetic right shift?

A logical shift fills the top with 0s; an arithmetic shift copies the sign bit. In 8 bits, 0x80 ≫ 1 is 0x40 (64) logically but 0xC0 (−64) arithmetically.

How do I rotate bits in C?

C has no rotate operator, but (x >> n) | (x << (8 − n)) on a uint8_t (with 0 < n < 8) rotates right, and compilers turn it into a single rotate instruction.

Related Digital Logic calculators

Enter your values to get the result with the formula, substituted values and an explanation of each step.

All engineering calculators