Bit Shift Calculator

Calculate left and right bit shifts with visual representation.

Bit width:
Shift type:

Understanding Bit Shifts

Left Shift (<<)

Shifts bits to the left, filling with zeros on the right. Equivalent to multiplying by 2^n.

5 << 2 = 20 (5 × 4)

Right Shift (>>)

Shifts bits to the right. Logical shift fills with zeros; arithmetic shift preserves the sign bit.

20 >> 2 = 5 (20 ÷ 4)

Code Examples

const a = 5;     // 0101
a << 1;          // 10 (1010) - multiply by 2
a << 2;          // 20 (10100) - multiply by 4
a >> 1;          // 2 (0010) - divide by 2
a >>> 1;         // 2 (logical right shift)

Frequently Asked Questions

What does bit shifting do?

Left shift (<<) moves bits left, filling with zeros. Equivalent to multiplying by 2^n. Right shift (>>) moves bits right, equivalent to dividing by 2^n (integer division).

What's the difference between logical and arithmetic shift?

Logical shift fills with zeros. Arithmetic right shift preserves the sign bit (fills with 1s for negative numbers). Left shift is the same for both.

Related Tools