Bit shift calculator
32-bit operations. Bits shifted past the ends are discarded, not wrapped.
Shifting left by n multiplies by 2 to the n; shifting right divides and truncates. 5 shifted left by 3 is 40. Bits pushed past the ends are discarded, so shifting is only equivalent to multiplying while nothing overflows.
How to use bit shifts
The two right shifts differ only for negative numbers, and the difference matters. A logical right shift fills from the left with zeros, so a negative number becomes a large positive one. An arithmetic right shift copies the sign bit, preserving the sign and behaving like division by a power of two. Most languages spell these differently — in JavaScript, >> is arithmetic and >>> is logical — and picking the wrong one is a classic source of bugs in code handling signed values.
Questions
Multiplies by two for each place shifted, as long as nothing overflows off the top.