What is a left bit shift operation?
A left bit shift (<<) moves all bits in a binary number to the left by a specified number of positions. Zeros are added on the right side, and bits that overflow are discarded. Each left shift by 1 position effectively multiplies the number by 2. See also our Hex to ASCII Converter.
What is a right bit shift operation?
A right bit shift (>>) moves all bits in a binary number to the right by a specified number of positions. The leftmost bits are filled with zeros (logical shift), and bits that fall off the right are discarded. Each right shift by 1 position effectively divides the number by 2.
Why use bit shifting instead of multiplication?
Bit shifting is much faster than multiplication or division operations because it's a basic CPU instruction. Left shifting by n positions multiplies by 2^n, and right shifting by n positions divides by 2^n, making it ideal for performance-critical applications.
What happens when bits are shifted out?
When bits are shifted beyond the bit width boundary, they are lost permanently. For example, in an 8-bit system, shifting 11111111 left by 1 position results in 11111110, where the leftmost 1 is discarded.
How do I calculate a left shift by 3 bits?
To left shift by 3 bits, move each bit 3 positions to the left and fill the rightmost 3 positions with zeros. For example: 5 (binary: 101) << 3 = 40 (binary: 101000). This multiplies the original number by 2^3 = 8.
What is the difference between different bit widths?
Bit width determines the maximum number that can be represented and affects overflow behavior. 8-bit can represent 0-255, 16-bit can represent 0-65535, and 32-bit can represent much larger numbers. Wider bit widths reduce the chance of overflow.
Does shifting always multiply or divide by 2?
Yes, for integer values. Left shifting by 1 position always multiplies by 2, and right shifting by 1 position always divides by 2 (rounded down). Shifting by n positions multiplies by 2^n or divides by 2^n respectively. You might also find our use the ADC Calculator useful.