← All tools and guides

Guide

Bit shifts and bit manipulation

Learn how left and right shifts work, where overflow comes from, and why integer width and signedness matter.

Left and right shifts

For non-negative integers with unlimited precision, shifting left by n positions multiplies the value by 2ⁿ. Shifting right by n positions performs integer division by 2ⁿ.

Fixed-width machine integers behave differently because shifted bits can fall outside the available width. Languages also differ in how they right-shift negative values, so width and signedness must be explicit in low-level work.

Why this calculator uses arbitrary precision

JavaScript’s ordinary bitwise operators first coerce values to 32-bit integers. This calculator uses BigInt instead, so values such as 2³¹ shifted left remain correct rather than wrapping to zero.

Bit shifts and bit manipulation page loaded