Skip to main content
Data / Number / Computer Science Tools

Bit Shift Calculator

Calculate left and right bit shifts - clearly distinguishes arithmetic (sign-preserving) from logical (zero-fill) right shift.

Enter a number and a shift amount - this tool calculates left shift, arithmetic right shift, and logical right shift, showing how they differ.

Arithmetic right shift preserves the sign bit (fills with 1s for negative numbers) - logical/unsigned right shift always fills with 0s, treating the value as unsigned. Shift counts are limited to 0-31 since JavaScript's bitwise operators work on 32-bit integers.

Arithmetic right shift preserves the sign bit (useful for signed integers); logical right shift always fills with zeros (used for unsigned values) - the difference only matters for negative numbers.

Arithmetic vs. Logical Right Shift

A left shift (<<) always fills vacated bits with zero. A right shift has two variants: arithmetic (>>) fills vacated bits with copies of the sign bit (preserving whether the number is negative), while logical (>>>) always fills with zeros regardless of sign.

How to Use It

  1. Enter an integer and a shift amount.
  2. View the left shift, arithmetic right shift, and logical right shift results side by side, with binary representations.

Limitations

Uses JavaScript's native 32-bit shift operators, matching standard integer shift behavior in most languages - shift amounts are taken modulo 32, and invalid (non-integer) shift counts are rejected rather than silently truncated.

Examples

ExpressionBinaryResult
5 << 2101 → 1010020 (5 × 4)
40 >> 3101000 → 1015 (40 ÷ 8)
-16 >> 2sign bit copied-4
-16 >>> 2zeros shifted in1073741820

Shifting left by n multiplies by 2n; an arithmetic right shift divides by 2n, rounding towards negative infinity.

Where Bit Shifts Are Used

  • Flags: 1 << 3 creates a mask with only bit 3 set, e.g. for permission or feature flags.
  • Packing values: combining RGB channels into one integer with (r << 16) | (g << 8) | b.
  • Fast arithmetic in performance-critical or embedded code.
  • Hash functions and checksums, which shift and mix bits.

Watch Out For

  • Shifting a 32-bit value by 32 does not give 0 in JavaScript - the shift amount wraps to 0.
  • Left-shifting into the sign bit turns a large positive number negative.
  • Different languages define right shifts on negative numbers differently; check yours.

Combine shifted values with the Bitwise Calculator, and inspect them with Decimal to Binary.

Frequently Asked Questions

It moves bits to the left, filling with zeros. Each left shift multiplies the number by 2, as long as no bits overflow.

An arithmetic right shift (>> in JavaScript) keeps the sign of negative numbers. A logical shift (>>>) fills with zeros, so negative numbers become large positive values.

JavaScript bitwise operators work on 32-bit integers, so values beyond that range are truncated.
Share this tool: