Perform left shift (<<), right shift (>>), and unsigned right shift (>>>) on integers. Visualize bit-level changes and understand binary shifting with an interactive 32-bit grid. Ideal for low-level programming, embedded systems, and algorithm design.
Bit shifting is a fundamental operation in computer science and digital electronics. It moves the bits of a binary number left or right, effectively multiplying or dividing by powers of two (for left/right logical shifts). However, arithmetic right shift preserves the sign bit, making it essential for signed integer division. The unsigned right shift (>>>) always fills with zeros, treating the number as unsigned. These operations are heavily used in cryptography, compression algorithms, embedded programming, and high-performance computing.
Left shift: x << n = x * 2ⁿ (when no overflow)
Right shift (arithmetic): x >> n ≈ floor(x / 2ⁿ) for signed numbers
Unsigned right shift: x >>> n = floor(x / 2ⁿ) mod 2³²
Internally, JavaScript converts every number to a 32-bit signed integer before applying shift operators, then converts back to a double-precision float. For left shift (<<), bits are shifted left, zeros fill the rightmost positions. Right shift (>>) preserves the sign bit (the most significant bit) and shifts copies of the sign bit into the left, known as sign extension. Unsigned right shift (>>>) shifts zeros into the leftmost positions, producing a non‑negative result. Our calculator replicates this behavior precisely, showing you both decimal results and 32‑bit two's complement binary representation.
The grid visualizer maps bits from index 31 (most significant) to 0 (least significant). We highlight each `1` bit in blue so you can track how the pattern changes after shifting. Using this tool, you can test edge cases like shifting -1, overflow, or shift amounts beyond 31 (mod 32).
| Operation | Example | Binary (32‑bit truncated) | Result (decimal) | Key property |
|---|---|---|---|---|
| Left shift (<<) | 14 << 2 | 000...001110 → 000...111000 | 56 | Multiplication by 2ⁿ |
| Right shift (>>) | -8 >> 2 | 111...111000 → 111...111110 | -2 | Sign extension, division truncates toward -∞ |
| Unsigned right shift (>>>) | -8 >>> 2 | 111...111000 → 001...111110 | 1073741822 | Zero-fill, always non-negative |
| Left shift overflow | 0x40000000 << 1 | 0100...0000 → 1000...0000 | -2147483648 | Signed overflow |
In embedded systems, registers are often manipulated via bit shifts. For example, to set bit 3 in a control register (value = 0b00001000), you write REG |= (1 << 3). Using our calculator, shifting 1 left by 3 yields 8 (0b1000). To clear bit 3: REG & ~(1 << 3). The interactive grid helps beginners see exactly which bit position changes. Engineers can precompute masks without writing test code.
Logical shift (used in unsigned right shift) simply moves bits and fills with zero, suitable for unsigned numbers. Arithmetic right shift (>>) replicates the highest bit (sign) to preserve the sign of a signed integer. For negative numbers, >> results division rounding toward negative infinity. For example, -9 >> 1 = -5 (floor(-4.5) = -5). Unsigned right shift ignores sign and gives a large positive number. These distinctions are critical when writing portable low-level code or emulating hardware behavior.