⬅️➡️ Bit Shift Calculator

Perform bit shift operations on binary numbers

How to Use This Calculator

1

Enter Binary Number

Input the binary number you want to shift. The calculator accepts only 0s and 1s. Examples: 1010, 1100, 1111. You can also enter signed binary numbers for arithmetic right shift.

2

Select Shift Type and Amount

Choose the shift type (Left, Right Logical, or Arithmetic Right) and enter the number of positions to shift. Left shift multiplies by 2^n, right shift divides by 2^n.

3

Review Results

The result shows the shifted binary number, decimal equivalent, and a step-by-step explanation of how the shift was performed. For arithmetic right shift, the sign bit is preserved.

Formula

Left Shift: value × 2^n

Right Shift: value ÷ 2^n

Arithmetic Right Shift: Preserves sign bit

How it works:

Bit shifting moves all bits in a binary number left or right by a specified number of positions. Left shift multiplies by 2^n, right shift divides by 2^n. This is one of the fastest operations in computer arithmetic.

Shift Types:

  • Left Shift (<<): Move bits left, fill right with zeros. Equivalent to multiplying by 2^n.
  • Logical Right Shift (>>>): Move bits right, fill left with zeros. Equivalent to dividing by 2^n (unsigned).
  • Arithmetic Right Shift (>>): Move bits right, fill left with sign bit. Preserves the sign of signed numbers.

Example 1: Left Shift 1010 by 2 (10 × 4 = 40)

Original: 1010 (10 in decimal)

Left shift by 2: Append 2 zeros

Result: 101000 (40 in decimal)

10 × 2² = 10 × 4 = 40 ✓

Example 2: Right Shift 1100 by 1 (12 ÷ 2 = 6)

Original: 1100 (12 in decimal)

Right shift by 1: Remove rightmost bit, fill left with 0

Result: 0110 (6 in decimal)

12 ÷ 2¹ = 12 ÷ 2 = 6 ✓

Example 3: Arithmetic Right Shift 1101 by 1 (-3 ÷ 2 = -2)

Original: 1101 (assuming signed, -3 in two's complement)

Arithmetic right shift by 1: Remove rightmost bit, fill left with sign bit (1)

Result: 1110 (-2 in two's complement)

-3 ÷ 2 = -2 (rounded down) ✓

Frequently Asked Questions

What is the difference between logical and arithmetic right shift?

Logical right shift (>>>) fills the left with zeros, treating the number as unsigned. Arithmetic right shift (>>) fills the left with the sign bit (0 for positive, 1 for negative), preserving the sign of signed numbers. For example, -8 >> 1 = -4 (arithmetic), but -8 >>> 1 = 2147483644 (logical, treated as unsigned).

Why are bit shifts so fast in computers?

Bit shifts are hardware-level operations that can be performed in a single CPU cycle. They don't require complex arithmetic - just moving bits and filling with zeros or sign bits. This makes them much faster than multiplication or division, even though shifting left is equivalent to multiplying by powers of 2.

When should I use left shift vs multiplication?

Use left shift when multiplying by powers of 2 (2, 4, 8, 16, etc.). It's faster and more efficient. For example, instead of `x * 8`, use `x << 3`. However, for readability and when multiplying by non-power-of-2 numbers, regular multiplication is often clearer.

What happens if I shift more positions than the number has bits?

For left shift, you'll get zeros (or a very large number if it overflows). For right shift, you'll get all zeros (logical) or all sign bits (arithmetic). In JavaScript, shifting beyond 32 bits can give unexpected results, so it's best to keep shifts within reasonable limits.

Are bit shifts used in real programming?

Yes! Bit shifts are commonly used for: optimizing multiplication/division by powers of 2, extracting specific bits from numbers, implementing data structures like bitmaps, working with flags and masks, and in low-level systems programming. They're especially important in embedded systems and performance-critical code.

Can bit shifts cause overflow or underflow?

Yes. Left shifting can cause overflow if the result exceeds the maximum value for the data type. Right shifting can cause underflow (result becomes 0) if you shift too many positions. In JavaScript, numbers are 64-bit floats, but bitwise operations work on 32-bit signed integers, so overflow can occur with large shifts.