---
slug: bit-shift-calculator
title: "Bit Shift Calculator"
category: developer
updated: 2026-11-17
canonical: https://calcseed.com/c/developer/bit-shift-calculator/
html: /c/developer/bit-shift-calculator/
---

# Bit Shift Calculator

Shift a number's bits left or right by any amount. See the decimal and binary result instantly.

## Quick answer

**Quick answer:** with the default inputs (8, 2 bits, left), the result is **32**. Change any input to update the result.

## Default calculation

Values computed by this calculator at exactly the default inputs listed below.

### Inputs (defaults)

| Input | Value | Unit |
| --- | --- | --- |
| Value | 8 |  |
| Shift by | 2 | bits |
| Direction | left |  |

### Outputs at these defaults

| Output | Value | Unit |
| --- | --- | --- |
| Result | 32 |  |

## Formula

```text
left: value × 2&#8319;    right: value ÷ 2&#8319;
```

## Inputs

| Variable | Type | Unit | Default |
| --- | --- | --- | --- |
| Value | number |  | 8 |
| Shift by | number | bits | 2 |
| Direction | select |  | left |

## Outputs

| Result | Format |
| --- | --- |
| Result | primary |
| Result | number |
| Result (binary) | text |

## How it works

### What the calculator returns

Enter a value, a shift amount and a direction, and you get the shifted result in decimal and in binary. The defaults are **8** shifted left by **2**, which gives **32**, binary **100000**.

Binary 1000 has a single bit at position 3, worth 8. Two left shifts move it to position 5, worth 32. That mechanical picture is the whole operation: the bits slide over and zeros fill the gap on the right.

### What a shift does to the bits

Moving every bit one place to the left doubles the value, because each bit now sits on a weight twice as large. Shifting *n* places multiplies by 2^*n*. Shifting right divides by 2^*n* and discards the bits that fall off the low end, which is why the right form has a floor in it.

The two directions are not exact inverses. 8 shifted left by 2 then right by 2 returns 8, but 9 shifted right by 1 gives 4 and shifting that back gives 8, because the discarded bit is gone. Any information that leaves the register does not come back.

### Worked example: 8 shifted left by 2

Eight is 1000 in binary, one bit at position 3. Shift left once: 10000, which is 16. Shift left again: 100000, which is 32. The single set bit moved from weight 2^3 to weight 2^5, and 2^5 = 32.

- 8 in binary: 1000
- After one left shift: 10000, decimal 16
- After two left shifts: 100000, decimal 32
- Arithmetic check: 8 × 2^2 = 8 × 4 = 32

Now run the same value to the right. 8 shifted right by 1 is 4, by 2 is 2, by 3 is 1, and by 4 is 0. Each step halves and rounds down, so the sequence collapses to zero in four steps rather than lingering at a fraction.

### Shift table for the default value

| Shift | 8 << n | 8 >> n |
| --- | --- | --- |
| 0 | 8 | 8 |
| 1 | 16 | 4 |
| 2 | 32 | 2 |
| 3 | 64 | 1 |
| 4 | 128 | 0 |
| 5 | 256 | 0 |

The left column doubles without limit until the value overflows the register. The right column hits zero as soon as every set bit has been shifted out, which for 8 happens at a shift of 4 because the highest bit sat at position 3. Larger values take longer to clear.

#### Right shifts truncate, they do not round

Nine shifted right by 1 is 4, not 4.5. The bit that represented the odd half is dropped, so the result is the floor of the division. Code that needs rounding has to add half the divisor before shifting, and code that assumes a shift is a clean division will quietly lose a unit on every odd number.

### Signed values and the two right shifts

JavaScript bitwise operators work on 32-bit signed integers. The right shift this calculator applies is the arithmetic one, which copies the sign bit into the vacated positions so that negative numbers stay negative. A separate logical shift fills with zeros instead, and it is the correct choice when you are moving bit patterns rather than doing arithmetic.

This tool accepts values from 0 upward, so you will not see a negative result from the sign extension here. It becomes relevant in code: −8 shifted right by 1 is −4 arithmetically, while the logical shift would produce 2,147,483,644 because the sign bit is treated as data.

### Where shifts earn their place

- Packing color channels: red << 16 | green << 8 | blue builds a 24-bit value from three bytes
- Reading flag bits: value & (1 << 5) tests bit 5 without touching the others
- Fast scaling by powers of two, which compilers emit for multiplication by 2, 4, 8 and 16
- Hashing and checksum routines, where mixing bits by shifting is cheap and spreads entropy
- Fixed-point arithmetic, where a shift converts between integer and fractional representations

The color packing example is the one most people meet first. Three channels of eight bits go into one 24-bit integer, and the reverse operation masks then shifts each channel back out. It is exact, and it takes three instructions rather than a conversion through strings.

### Overflow and the 32-bit ceiling

Left shifts discard whatever leaves the top of the register. In a 32-bit signed context, 1 shifted left by 31 produces −2,147,483,648, because the set bit lands in the sign position. Shifting by 32 or more is treated as a shift modulo 32, so 1 << 32 returns 1 rather than 0 — a rule that has surprised many people debugging a loop.

The input range here stops at 2,147,483,647 and the shift amount at 31, which keeps every operation inside the signed 32-bit model. Values that would overflow still wrap, because that is what the underlying operators do, so a large shift of a large value can produce a negative number. If you need 64-bit behaviour, the arithmetic has to happen in a language or a type that supports it.

#### Rotate is a different operation

A rotate moves the bits that leave one end back in at the other, so nothing is lost and the value keeps all of its information. Many processors have rotate instructions and cryptography uses them heavily. JavaScript has no rotate operator, so the idiom is (x >> (32 − n)) — a shift in each direction combined with OR.

### Where shifting goes wrong

The most common error is using a right shift as a division when the value can be negative. Arithmetic shift rounds toward negative infinity, so −9 >> 1 is −5, while −9 / 2 truncates toward zero and gives −4. The two answers differ by one, and the bug appears only on negative inputs, which is exactly when tests are thinnest.

The second is forgetting that shift counts wrap in JavaScript and in many CPUs. A loop that shifts by a computed amount can silently do nothing when that amount reaches 32. Mask the count or assert its range before shifting.

## FAQ

### What is 8 shifted left by 2?

32. Each left shift doubles the value, so 8 becomes 16 then 32, and the binary form goes from 1000 to 100000.

### Does a left shift always multiply by two?

Per position, yes, as long as no set bit is pushed past the top of the register. Once bits leave the top, the value wraps and the doubling rule stops holding.

### What is 9 shifted right by 1?

4, not 4.5. The low bit is discarded, so a right shift floors the division and loses the remainder.

### What is the difference between &gt;&gt; and &gt;&gt;&gt;?

The arithmetic shift copies the sign bit into the vacated positions, while the logical shift fills with zeros. For negative numbers they give different results: −1 >> 1 is −1, and −1 >>> 1 is 2,147,483,647.

### Why does 1 &lt;&lt; 31 give a negative number?

In 32-bit signed arithmetic the set bit lands in the sign position, which is read as −2,147,483,648. That is the same pattern an unsigned view would call 2,147,483,648.

### What happens if I shift by 32?

The count is taken modulo 32, so 1 << 32 returns 1. This calculator caps the shift at 31 to stay inside the model.

### Is shifting faster than multiplying?

On modern processors the difference is negligible for a single operation, since both execute in one cycle. Shifts still express intent clearly when you are manipulating bit patterns rather than numbers.

### How do I extract a byte with shifts?

Shift right to move the byte to the low end, then mask with 0xFF. For the green channel of a packed color: (value >> 8) & 0xFF.

### Can I shift by a negative amount?

No. A negative count has no meaning as a direction, because direction is a separate choice here. In code it usually produces undefined behaviour or a wrapped count.

### What does shifting zero do?

Zero stays zero in either direction, at any shift amount. There are no set bits to move, so the result is always 0.

## Method and sources

Methodology: Conversions and formats follow the relevant IETF RFCs and IEEE standards, including RFC 4648 for Base64 and RFC 791 for IPv4 addressing.

Last updated: 2026-11-17.
- Bit shift identities: value << n = value × 2ⁿ and value >> n = floor(value / 2ⁿ).
