Bitwise Shift Calculator
Left-shift or right-shift an integer — arithmetic/signed >> or logical/unsigned >>> — at a chosen bit width (8/16/32/64), showing the before/after binary pattern plus the decimal and hex result.
Input
Decimal (optionally negative) or unsigned 0x-hex, e.g. -8 or 0xF0.
Number of bit positions to shift. Amounts ≥ the bit width clamp to a full shift (result 0, or -1 for arithmetic right shift of a negative value); negative amounts are treated as 0.
Output
| Property | Value |
|---|---|
| No data yet | |
Guides
The Bitwise Shift Calculator moves the bits of an integer left or right and shows you the exact before-and-after binary pattern, plus the decimal and hexadecimal result. It's built for anyone who needs to reason about shift operations precisely — students learning two's complement, developers debugging a bitmask, or engineers double-checking a fast-multiply/divide trick — rather than just getting a number back.
Arithmetic vs. logical shift
Left shift (<<) always works the same way: bits move toward the most significant position and zeros fill in from the right. Bits shifted past the chosen bit width are dropped.
Right shift has two different meanings, and picking the wrong one is a classic source of bugs:
- Arithmetic right shift (
>>, signed) preserves the sign of the value. If the number is negative (its top bit is 1), the vacated high bits are filled with 1s, so the result stays negative — the same rule as integer division that rounds toward negative infinity. This is what most languages'>>operator does on signed integers. - Logical right shift (
>>>, unsigned) ignores sign entirely. The vacated high bits are always filled with 0s, so a shifted negative number becomes a large positive one. This is the right choice when you're treating the value as a raw bit pattern rather than a signed quantity — extracting color channels from a packed pixel, for example.
Because the difference only shows up on negative numbers, it's easy to test correctly on positive values and then get surprised in production. This calculator lets you flip between the two on the same input to see exactly where they diverge.
How to use it
- Enter a Value — a decimal integer (negative numbers are fine, e.g.
-8) or an unsigned hex literal like0xF0. - Enter a Shift Amount — how many bit positions to shift.
- Choose a Shift Direction: left shift, arithmetic (signed) right shift, or logical (unsigned) right shift.
- Choose a Bit Width — 8, 16, 32, or 64 bits. This determines how your value is padded and where bits fall off the edge; the same decimal value can shift differently depending on the width you choose.
The result table shows the original value's binary pattern padded to your chosen width, the binary pattern after the shift, the decimal result, and the hex result — updated instantly as you change any field.
FAQ
What happens if the shift amount is larger than the bit width? The result is what you'd get from shifting every original bit out: 0 for left shift and logical right shift, and either 0 or -1 (all bits set) for arithmetic right shift, depending on whether the value was non-negative or negative.
What happens with a negative shift amount? It's treated as 0 — the value passes through unchanged.
Why does a hex input like 0xF0 shift differently than the decimal 240?
It doesn't — 0xF0 and 240 are the same value. Hex input is just a more convenient way to type an exact bit pattern when you're thinking in binary/hex terms rather than decimal.
Why did my negative number become a huge positive number? You likely used logical (unsigned) right shift on a negative value. That's expected: logical shift has no concept of sign, so it fills with 0s instead of preserving the sign bit. Switch to arithmetic right shift if you want the sign preserved.
Is this the same as the general Bitwise Calculator? No — the Bitwise Calculator handles AND/OR/XOR/NOT plus shifts on a pair of numbers. This tool is specifically for exploring shift behavior: it adds a bit-width selector and a full binary before/after readout so you can see precisely which bits moved, which bits fell off, and which bits were filled in.
Privacy
All calculations run entirely in your browser. Your input value is never sent to a server.