What is a bit shift?
A bit shift moves the binary digits of an integer left or right by a chosen number of positions. Shifting is a fundamental operation in programming, low-level optimization, graphics, hashing, and embedded systems. A left shift (n << k) moves bits toward the most-significant end, filling with zeros, while a right shift (n >> k) moves them toward the least-significant end.
How to use this calculator
Enter the integer n, the shift amount k (in bits), and choose the direction. The calculator returns the resulting decimal value. This tool uses 64-bit signed integer arithmetic, matching the behavior of most programming languages.
The formula explained
Each left shift by one position doubles the number, so shifting left by k positions multiplies by 2k: $$\text{Result} = \text{Number (n)} \ll \text{Shift (k)} = n \times 2^{k}$$ Each right shift by one position halves the number with truncation, so a right shift by k performs integer division by 2k: $$\text{Result} = \text{Number (n)} \gg \text{Shift (k)} = \left\lfloor \frac{n}{2^{k}} \right\rfloor$$ This is why shifts are far cheaper than multiplication or division on hardware.
Worked example
Take \(n = 16\) and shift left by \(k = 2\). In binary 16 is 10000. Shifting left twice appends two zeros: 1000000, which is 64. Mathematically, $$16 \times 2^{2} = 16 \times 4 = 64$$ Going the other way, $$64 \gg 2 = \left\lfloor \frac{64}{4} \right\rfloor = 16$$ returns the original value.
Powers of Two Reference Table
A left shift by \(k\) multiplies a number by \(2^k\); a right shift by \(k\) divides by \(2^k\) (discarding the remainder for integers). Use this table to read off the multiplier or divisor for a given shift amount instantly.
| Shift \(k\) | \(2^k\) (decimal) | Meaning of \(\ll k\) / \(\gg k\) |
|---|---|---|
| 0 | 1 | no change |
| 1 | 2 | \(\times 2\) / \(\div 2\) |
| 2 | 4 | \(\times 4\) / \(\div 4\) |
| 3 | 8 | \(\times 8\) / \(\div 8\) |
| 4 | 16 | \(\times 16\) |
| 5 | 32 | \(\times 32\) |
| 6 | 64 | \(\times 64\) |
| 7 | 128 | \(\times 128\) |
| 8 | 256 | \(\times 256\) (1 byte) |
| 9 | 512 | \(\times 512\) |
| 10 | 1,024 | \(\times 1024\) (1 KiB) |
| 11 | 2,048 | \(\times 2048\) |
| 12 | 4,096 | \(\times 4096\) |
| 13 | 8,192 | \(\times 8192\) |
| 14 | 16,384 | \(\times 16384\) |
| 15 | 32,768 | \(\times 32768\) |
| 16 | 65,536 | \(\times 65536\) (2 bytes) |
| 17 | 131,072 | |
| 18 | 262,144 | |
| 19 | 524,288 | |
| 20 | 1,048,576 | \(\times\) 1 MiB |
| 32 | 4,294,967,296 | 32-bit boundary |
| 63 | 9,223,372,036,854,775,808 | top bit of a 64-bit signed integer |
FAQ
Does a left shift ever lose data? Yes — bits shifted beyond the integer's width are discarded (overflow). Within 64 bits this calculator preserves the value.
What happens with negative numbers on a right shift? This calculator uses an arithmetic (signed) right shift, so the sign bit is preserved and negative numbers stay negative.
Why use shifts instead of multiply or divide? Bit shifts are single-cycle operations on most CPUs, making them a fast way to multiply or divide by powers of two.