Bit Shift Calculator – Left Shift, Right Shift, Arithmetic & Logical

Perform left shift, logical right shift, and arithmetic right shift with bit-by-bit visualization, shift tables, sign extension, and multiply/divide equivalences.

Integer to shift
Number of bit positions (0–31)
Shift Result (Decimal)
168
Shift bits left by 2 — equivalent to multiplying by 2^2 = 4
Before (Binary)
0b10101010
Decimal: 170 | Hex: 0xAA
After (Binary)
0b10101000
Decimal: 168 | Hex: 0xA8
Multiply/Divide Equiv.
680.00
170 × 2^2 = 680
Bits Lost
1
1 set bit(s) shifted out and discarded
Sign Bit
1
MSB = 1 → Negative in signed | Signed value: -86
Signed After
-88
8-bit signed interpretation of result
Bit Width
8-bit
Range: 0–255 (unsigned)

Bit Movement Visualization

1
0
1
0
1
0
1
0
Before
← ← ← shift by 2
1
0
1
0
1
0
0
0
After
🔵 Original bits🟢 Set bits afterNew fill bits

Shift Table (value = 170)

ShiftExpressionResultBinary
0170 << 017010101010
1170 << 18401010100
2170 << 216810101000
3170 << 38001010000
4170 << 416010100000
5170 << 56401000000
6170 << 612810000000
7170 << 7000000000

Shift Types Comparison

TypeOperatorFill BitsUse Case
Left Shift<<0 (right side)Multiply by 2ⁿ, create bit masks
Logical Right>>>0 (left side)Unsigned division by 2ⁿ
Arithmetic Right>>Sign bit (left side)Signed division by 2ⁿ, preserves sign
Planning notes, formulas, and examples

About the Bit Shift Calculator – Left Shift, Right Shift, Arithmetic & Logical

Bit shifting is one of the most fundamental and performance-critical operations in computing. A left shift moves every bit toward the most significant position, filling vacated positions with zeros — effectively multiplying the number by a power of two. A right shift does the opposite, dividing by a power of two, but with an important distinction: logical right shift fills with zeros (treating the value as unsigned), while arithmetic right shift preserves the sign bit (treating the value as signed).

Left shifts are used throughout systems programming for creating bitmasks, packing data into compact binary formats, and performing fast multiplication. Right shifts handle fast division, extracting specific bit fields, and sign-extending values during type conversions. The choice between arithmetic and logical right shift affects whether negative numbers stay negative or wrap to large positive values — a common source of subtle bugs.

This calculator lets you experiment with all three shift types across 4-bit to 32-bit widths. The bit-movement visualization shows exactly which bits move where, which bits are lost off the edge, and which new bits are filled in. The shift table displays all possible shift amounts for your value, making it easy to spot patterns like doubling (left shift) and halving (right shift). Sign bit tracking and signed/unsigned interpretations help you understand the difference between arithmetic and logical shifts.

When This Page Helps

Tracking which bits fall off the edge, which fill in, and whether the sign bit propagates correctly is hard to do in your head — especially for arithmetic right shifts on negative numbers. This calculator shows the binary before and after, highlights each bit's movement, and displays the equivalent multiplication or division so you can validate your reasoning against the output. Embedded programmers use it to design bit-packing schemes, systems students verify homework on sign extension, and anyone debugging shift-related bugs can see exactly what the hardware produces.

How to Use the Inputs

  1. Enter the integer value you want to shift.
  2. Set the shift amount (0–31 bit positions).
  3. Choose left shift (<<) or right shift (>>).
  4. For right shifts, choose Logical (>>> fills 0s) or Arithmetic (>> preserves sign).
  5. Select a bit width (4, 8, 16, or 32 bits).
  6. View the result along with binary before/after and the multiply/divide equivalence.
  7. Check the bit-movement visualization to see exactly how bits relocate.
  8. Browse the shift table to see results for all shift amounts.
Formula used
Left shift: A << n = A × 2ⁿ. Logical right shift: A >>> n = floor(A / 2ⁿ) (unsigned). Arithmetic right shift: A >> n preserves the MSB (sign bit) while shifting.

Example Calculation

Result: 168

170 = 10101010. Left shift by 2: 10101000 = 168 (in 8-bit). Top 2 bits (10) are lost; bottom 2 zeros fill in. 170 × 4 = 680, but 680 mod 256 = 168 due to 8-bit overflow.

Tips & Best Practices

  • Left shifting by n is the same as multiplying by 2ⁿ (watch for overflow).
  • Logical right shift by n divides unsigned values by 2ⁿ (truncating).
  • Arithmetic right shift preserves the sign bit — crucial for signed integers.
  • In JavaScript, << is left shift, >> is arithmetic right shift, >>> is logical right shift.
  • Shifting by 0 returns the original value — useful as a no-op identity check.
  • Be careful: shifting by more than the bit width is undefined behavior in C/C++.

Left Shift as Fast Multiplication

A left shift by n positions is equivalent to multiplying by 2ⁿ. Compilers routinely replace `x * 8` with `x << 3` because shift hardware is simpler and faster than a full multiplier. The caveat is **overflow**: in an 8-bit register, 170 << 2 does not give 680 but 168 (680 mod 256), because the two most-significant bits are lost. Understanding overflow is critical in embedded systems where registers are narrow and in cryptographic code where every bit matters.

Right Shift and the Sign Debate

Logical right shift (>>>) fills vacated high bits with 0, which correctly divides *unsigned* values by 2ⁿ. Arithmetic right shift (>>) copies the sign bit (MSB) into the vacated positions, preserving the sign of *signed* values. For example, −8 in 8-bit two's complement is 11111000; an arithmetic right shift by 1 gives 11111100 = −4, while a logical right shift gives 01111100 = 124. Getting this wrong is a subtle bug because it only manifests for negative inputs, which may be rare in test suites.

Practical Bit-Shift Patterns in Code

- **Power-of-two multiply/divide**: `1 << n` gives 2ⁿ, useful for creating bitmasks like `(1 << 5) - 1 = 31`. - **Extracting a field**: shift right to move the field to the LSB, then AND with a mask: `(reg >> 4) & 0xF` extracts bits 7–4. - **Packing two values**: `(high << 8) | low` packs two bytes into a 16-bit word. - **Fast floor division**: `x >> 1` is a fast floor(x/2) for non-negative x; for signed x, beware that C's `>>` is implementation-defined. - **Pixel manipulation**: colour channels are often packed in 32 bits (ARGB). Extracting Blue: `pixel & 0xFF`. Extracting Green: `(pixel >> 8) & 0xFF`.

Understanding these idioms is essential for systems programming, graphics, and protocol parsing.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • Logical right shift (>>>) fills vacated bits with 0. Arithmetic right shift (>>) fills with the sign bit (MSB), preserving the sign of negative numbers. For positive numbers, both produce the same result.