Free Online Engineering Tools
Home / Bit Shift Calculator

Bit Shift Calculator

Compute left shift (<<) and right shift (>>) on any integer — instant binary, decimal & hex results, visual bit movement diagram, logical vs arithmetic shift guide, powers-of-2 reference, and code examples for C, Python, Java & JavaScript.

🔢 Bit Shift Calculator

Calculate bit shift operations (<<, >>) with binary and decimal results

Input
ℹ️ Left shift (<<) multiplies by 2n
Result = Number × 2n
Quick Reference
OperationEffectExample (x = 8)
x << 1x × 28 << 1 = 16
x << 2x × 48 << 2 = 32
x << 3x × 88 << 3 = 64
x >> 1x ÷ 28 >> 1 = 4
x >> 2x ÷ 48 >> 2 = 2
x >> 3x ÷ 88 >> 3 = 1
Why Bit Shifts Are Useful
  • 🖥️ Low-level programming
  • Performance optimization
  • 🎮 Graphics & game engines
  • 🔌 Embedded systems
  • 🧮 Binary data processing
Results
Expression
5 << 1
Decimal Result
10
Binary Representation
Original (5)
Result (5 << 1)
Formula
y = x × 2n
x = original number
n = number of positions shifted
Binary Place Values
128
27
64
26
32
25
16
24
8
23
4
22
2
21
1
20
How It Works
Left Shift (<<) – bits move left, 0s added on the right
9 (00001001) << 2 = 36 (00100100)
0 0 0 0 1 0 0 1
<< 2
0 0 1 0 0 1 0 0
Right Shift (>>) – bits move right, 0s added on the left
40 (00101000) >> 3 = 5 (00000101)
0 0 1 0 1 0 0 0
>> 3
0 0 0 0 0 1 0 1
Bit Shift Operations (Visual)
Left Shift (<<)
MSB LSB 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
Right Shift (>>)
MSB LSB 1 0 1 1 0 0 1 1 0 0 1 0 1 1 0 0 1

Left Shift (<<): Moves bits to the left by the specified amount. Adds zeros on the right. This operation multiplies the number by 2 for each shift.

Right Shift (>>): Moves bits to the right by the specified amount. Discards bits shifted off. This operation divides the number by 2 for each shift (ignoring remainders).

More Examples
Left Shift (<<)
  • • 3 << 1 = 6
  • • 3 << 2 = 12
  • • 7 << 3 = 56
  • • 12 << 2 = 48
Right Shift (>>)
  • • 16 >> 1 = 8
  • • 16 >> 2 = 4
  • • 19 >> 1 = 9
  • • 40 >> 3 = 5
Example in Code (C)
int a = 5;
int b = a << 2;  // 20

int c = 32;
int d = c >> 3;  // 4

Bit Shift Calculator — Complete Guide to Left Shift (<<) and Right Shift (>>)

This bit shift calculator instantly computes left shift (<<) and right shift (>>) operations on any integer with binary, decimal, and hexadecimal results, a visual bit movement diagram, a place-value chart, logical vs arithmetic right shift explanation, and code examples for C, Python, Java, and JavaScript. Bit shifting is one of the most fundamental and efficient operations in digital computing — every CPU executes it in a single clock cycle, and it is the basis for fast power-of-two arithmetic, color channel extraction, hardware register manipulation, and embedded systems programming.

What Is a Bit Shift?

A bit shift moves all the binary digits of an integer a fixed number of positions to the left or right. Left shift (<<) slides every bit toward the most significant end, filling the vacated right positions with zeros — equivalent to multiplying by a power of two. Right shift (>>) slides every bit toward the least significant end, discarding the bits that fall off — equivalent to integer floor division by a power of two. Bits that move beyond the storage width of the data type are simply discarded.

Quick Reference: Bit Shift Formulas

OperationOperatorFormulaWorked Example
Left Shiftx << nx × 2^n (no overflow)5 << 3 = 5 × 8 = 40
Right Shift (unsigned)x >> nfloor(x ÷ 2^n)40 >> 3 = 40 ÷ 8 = 5
Right Shift (signed neg.)x >> nArithmetic: sign bit propagates-8 >> 1 = -4
Single left shiftx << 1x × 27 << 1 = 14
Single right shiftx >> 1floor(x ÷ 2)7 >> 1 = 3
Shift by 0x << 0x (unchanged)42 << 0 = 42

Worked Examples

⬅️ Left Shift: 5 << 3 = 40
Givenx = 5 = 00000101 (8-bit)  |  n = 3 positions left
Step 1Write binary: 0 0 0 0 0 1 0 1   (place values: 128 64 32 16 8 4 2 1)
Step 2Shift left 3: 0 0 1 0 1 0 0 0 → 00101000   (fill right 3 with zeros, top 3 discarded)
Step 3Verify: x << n = x × 2^n = 5 × 2³ = 5 × 8 = 40 ✓
Result5 << 3 = 40  |  Binary: 00101000  |  Hex: 0x28  |  Octal: 050
➡️ Right Shift: 185 >> 2 = 46
Givenx = 185 = 10111001 (8-bit)  |  n = 2 positions right
Step 1Write binary: 1 0 1 1 1 0 0 1   (place values: 128 64 32 16 8 4 2 1)
Step 2Shift right 2: 0 0 1 0 1 1 1 0 → 00101110   (fill left 2 with 0s, right 2 bits 01 discarded)
Step 3Verify: floor(185 ÷ 4) = floor(46.25) = 46 ✓   (remainder 1 discarded)
Result185 >> 2 = 46  |  Binary: 00101110  |  Hex: 0x2E  |  1 remainder discarded

Powers of Two Reference — Left Shift Results

Shift nMultiplier1 << n (decimal)HexBit pattern (32-bit)
0×110x00000001...00000001
1×220x00000002...00000010
2×440x00000004...00000100
3×880x00000008...00001000
4×16160x00000010...00010000
7×1281280x00000080...10000000
8×2562560x00000100...1 00000000
15×3276832 7680x00008000...1 0000...0000
16×6553665 5360x00010000
24×1677721616 777 2160x01000000
31×21474836482 147 483 6480x80000000MSB only

Logical vs Arithmetic Right Shift — Complete Comparison

PropertyLogical Right ShiftArithmetic Right Shift
Vacated left bitsAlways filled with 0Filled with copy of sign bit
Positive numbersSame result as arithmeticSame result as logical
Negative numbersBecomes large positiveStays negative (rounds toward -∞)
Example: -8 >> 1= 2147483644 (32-bit unsigned)= -4 (preserves sign)
C / C++Use unsigned type: (unsigned)x >> nSigned type >> (impl-defined, usually arith.)
Java>>> operator>> operator
JavaScript>>> operator>> operator
PythonN/A (arbitrary precision)>> always arithmetic
Rustu-type (u32, u64) uses >>i-type (i32, i64) uses >>

Overflow — When Left Shift Loses Bits

Expression8-bit ResultWhat Happened
1 << 710000000 = 128 (unsigned) / -128 (signed)Bit moved into sign bit
1 << 800000000 = 0Bit shifted out of 8-bit width entirely
255 << 111111110 = 254 (bit 0 lost)High bit discarded
128 << 100000000 = 0Only set bit shifted out

Bit Shifts in Programming Languages

LanguageLeft ShiftRight Shift (arith.)Right Shift (logical)Notes
C / C++<<>> (signed)>> (unsigned type)Signed right shift = impl-defined
Java<<>>>>>int=32-bit, long=64-bit
JavaScript<<>>>>>32-bit signed for << and >>
Python<<>>N/AArbitrary precision — no overflow
C#<<>>>>> (C# 11+)
Rust<<>> (i-type arith.)>> (u-type logical)Panics on overflow in debug mode
x86 ASMSHL / SALSARSHRSeparate arithmetic/logical instructions

Practical Applications of Bit Shifts

Fast Power-of-Two Arithmetic

x << n = x × 2^n and x >> n = floor(x ÷ 2^n) for unsigned values. On older processors, shift instructions execute in one cycle while multiply may take 20+. Modern compilers automatically convert multiplication by constants to shifts, but explicit shifts make the intent clear in embedded systems where every instruction counts.

Colour Channel Packing and Unpacking

A 32-bit ARGB pixel packs four 8-bit channels into one integer. Unpacking: alpha = (pixel >> 24) & 0xFF; red = (pixel >> 16) & 0xFF; green = (pixel >> 8) & 0xFF; blue = pixel & 0xFF. Repacking: pixel = (a << 24) | (r << 16) | (g << 8) | b. This is used in every image processing library.

Hardware Register Bit-Field Access

Microcontroller peripheral registers pack multiple fields into one word. To read a 3-bit field starting at bit 4: field = (reg >> 4) & 0x7. To write it: reg = (reg & ~(0x7 << 4)) | (value << 4). This idiom appears in every embedded driver.

Fixed-Point Arithmetic

Fixed-point numbers represent fractions by treating the lower n bits as the fractional part. Multiplying two Q16.16 fixed-point numbers: result = (a * b) >> 16. Shifting maintains precision without floating-point hardware, used in digital signal processors and game physics.

Cryptography and Hashing

Bit rotation (left or right rotate — a shift where bits that fall off one end are reinserted at the other) is used in SHA-256, MD5, and AES. Implemented as: rotate_left(x, n) = (x << n) | (x >> (32 - n)).

Frequently Asked Questions

What does 1 << n mean?

1 << n creates a bitmask with exactly bit position n set to 1 and all others 0. For example, 1 << 3 = 8 = 0b00001000. This is used constantly in embedded code to target specific register bits: reg |= (1 << 5) sets bit 5.

Is left shift always the same as multiplying by 2?

For unsigned integers and values that don't overflow the data type width, yes — x << 1 = x × 2, x << n = x × 2^n. Overflow occurs when a 1-bit is shifted beyond the MSB, causing the result to wrap around or become 0.

What is the difference between >> and >>> in Java?

>> is the arithmetic right shift — it copies the sign bit into vacated positions, so negative numbers stay negative. >>> is the logical right shift — it always fills with 0s, making negative signed integers become large positive values. Python has no >>> because its integers have arbitrary precision and >> always behaves arithmetically.

What is a bit rotation vs a bit shift?

A shift discards bits that fall off one end. A rotation wraps them around to the other end — bits shifted off the MSB reappear at the LSB (left rotation) or vice versa (right rotation). Rotations are common in cryptographic algorithms and are implemented as: rotl(x,n) = (x << n) | (x >> (bits-n)).

Why is 7 >> 1 = 3 and not 3.5?

Right shift performs integer floor division: floor(7 ÷ 2) = 3. The remainder (the bit that falls off) is discarded. This is why right shift is used for fast integer halving but cannot represent fractional results.

Related Calculators