Skip to content
Math

Bit Shift Calculator

Enter any integer, choose the shift direction and number of positions, and see the result in binary, decimal, hex, and octal instantly. You can pick between logical right shift (fills with zeros) and arithmetic right shift (preserves the sign bit), choose your bit width (8, 16, or 32), and get a full step-by-step explanation of exactly which bits moved where.

Your details

Choose the number system your input value is written in.
The integer to shift. Enter in the base selected above. For binary, hex, or octal the field still uses decimal digits internally; switch to decimal for those bases or type the number in decimal equivalents.
How many bit positions to shift left or right.
bits
Left shift multiplies by 2 per position. Logical right shift divides unsigned; arithmetic right shift preserves the sign bit for signed integers.
The register width. Results are masked to this many bits, and overflow bits are discarded.
Result (decimal)
52

Unsigned decimal value of the shifted result

Result (signed decimal)52
Result (binary)0011 0100
Result (hexadecimal)0x34
Result (octal)0o64
Input (binary)0000 1101
Bits shifted out00
Equivalent multiplicationx * 2^2 = x * 4
Result (unsigned)52
Result (signed)52

13 shifted left by 2 = 52 (unsigned), 52 (signed)

  • Left shift by 2 is equivalent to multiplying by 4. The result fits within 8 bits.
  • In 8-bit representation, the signed range is -128 to 127 and the unsigned range is 0 to 255.

Next stepBit shifts are the fastest way to multiply or divide by powers of 2 at the CPU level. They are also used to isolate or set individual bits using bitwise AND/OR masks.

What is a bit shift?

A bit shift moves every bit in a binary number a certain number of positions to the left or right. Bits that fall off the end of the register are discarded, and the positions that open up on the other side are filled with either zeros or, in the case of arithmetic right shift, a copy of the original sign bit. Bit shifts are one of the cheapest operations a CPU can perform and are used everywhere from graphics processing to cryptography to compiler optimizations.

Left shift vs. right shift

A left shift by n positions is mathematically identical to multiplying by 2^n, provided the result fits within the register. For example, 13 << 2 gives 52 because 13 * 4 = 52. A right shift by n positions is integer division by 2^n. There are two right-shift variants. Logical right shift (>>>) always inserts zeros on the left, treating the number as unsigned. Arithmetic right shift (>>) copies the sign bit (the most significant bit) into the vacated positions, which correctly halves a negative two's complement integer: -4 >> 1 gives -2, not 126.

Signed vs. unsigned interpretation

Modern computers store integers using two's complement notation for signed types. In an 8-bit register, bit patterns 10000000 through 11111111 represent the values -128 through -1 when the type is signed, but 128 through 255 when unsigned. This calculator shows both interpretations side by side so you can see the effect a shift has regardless of how the host language declares the type. Languages like C treat the sign of a right shift as implementation-defined for signed types, while JavaScript's >>> operator always performs a logical (unsigned) shift.

Practical uses of bit shifting

Bit shifts appear constantly in low-level and systems programming. Common patterns include fast powers of 2 (x << 3 is always cheaper than x * 8), reading and writing hardware registers bit by bit, packing multiple small values into a single integer (bit fields), generating bitmasks (1 << n sets bit n), and checking whether a specific bit is set (x & (1 << n)). In cryptographic hash functions such as SHA-256 shifts and rotations are the primary mixing operations. Understanding what happens at the bit level makes debugging unexpected negative values, overflow, and mask logic much easier.

Bit shift operations at a glance

OperationSymbolFill bitsEffectExample
Left shift<<Zeros on rightMultiply by 2 per step13 << 2 = 52
Logical right shift>>>Zeros on leftUnsigned divide by 2 per step52 >>> 2 = 13
Arithmetic right shift>>Sign bit on leftSigned divide by 2 per step-4 >> 1 = -2
Overflow (left)<<n/aHigh bits discarded by register width200 << 2 = 800 -> 32 (8-bit)
Underflow (right)>>>n/aLow bits lost permanently1 >>> 1 = 0

All results are for an 8-bit register unless noted.

Frequently asked questions

Why does left-shifting a number sometimes give a negative result?

When you left shift a value far enough, the result bit pattern sets the most significant bit (the sign bit) to 1. In a signed integer type that is interpreted as a negative two's complement value. For example, 64 (01000000 in 8 bits) shifted left by 1 becomes 128, but in signed 8-bit arithmetic the pattern 10000000 equals -128. This is overflow, and whether it is defined behavior depends on the language - in C it is undefined for signed types, while in JavaScript all bitwise operators work on 32-bit signed integers.

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

In languages like Java and JavaScript, >> is an arithmetic right shift that copies the sign bit into vacated positions, preserving the sign of a negative number. >>> is a logical (unsigned) right shift that always inserts zeros, ignoring any sign. For positive numbers both produce the same result. For negative numbers, >> keeps the result negative (halving it), while >>> produces a large positive number because the sign bit is replaced with 0.

Can a bit shift replace multiplication or division?

Yes, for powers of 2. x << n equals x * 2^n and x >>> n equals floor(x / 2^n) for unsigned values. Modern compilers do this substitution automatically when optimizing, so you rarely need to write shifts by hand for performance. The main reasons to write explicit shifts in application code are clarity (showing you are working at the bit level) or when implementing protocols and data structures that explicitly pack values into bit fields.

What happens to bits that are shifted out of the register?

They are discarded. In most programming languages and CPUs there is no way to retrieve them once the operation is complete. Some processor instruction sets expose a carry flag that captures the last bit shifted out, and languages like Rust provide rotate_left and rotate_right functions that wrap the shifted-out bits back into the other end instead of discarding them (circular shift).

What bit width should I use?

Choose the width that matches your target data type: 8 bits for a byte or uint8_t, 16 bits for a short or uint16_t, and 32 bits for an int, long, or uint32_t in most C-family languages. JavaScript bitwise operators always work on 32-bit integers. The bit width matters because it determines when overflow occurs and how the signed range is interpreted.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…