Shifting bits is the fastest way for a processor to multiply or divide by powers of two. It is used in hashing, graphics, compression, cryptography and to extract fields from packed binary data.
How to use the Bit Shift Calculator
- Representation
- Number format
- Number
- Direction
- Number of positions
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
Choose the bit width, input format, direction and number of positions. A left shift drops bits that fall off the top; a logical right shift fills with zeros; an arithmetic right shift copies the sign bit so negative numbers stay negative.
Formula
x << n = x·2ⁿ (bits shifted out are lost) · x >>> n = ⌊x/2ⁿ⌋ (zeros enter) · x >> n keeps the sign bit
Worked example
Inputs: Representation: 8-bit; Number format: Binary; Number: 00010111; Direction: Left (<<); Number of positions: 2.
Results: Result (binary) = 0101 1100; Before the shift = 0001 0111; Result (decimal, unsigned) = 92; Result (decimal, signed) = 92; Result (octal) = 134.
Key terms
- Arithmetic shift
- A right shift that preserves the sign bit.
Frequently asked questions
What does a left shift by 1 do?
Doubles the number (as long as no bit falls off).
What is the difference between >> and >>>?
>> keeps the sign (arithmetic); >>> fills with zeros (logical).
What happens to bits shifted out?
They are discarded.
Is shifting faster than multiplying?
On simple processors yes; modern compilers do it automatically.