The shift operation of a microprocessor is an amazingly useful function which generally takes very few cycles to complete, often as few as one. It can be used for (among many other things) multiplication and division by two (to a point.) Using this feature repeatedly can also multiply and divide by powers of two through repetition.

Let us look at the base 10 number "1" as represented in one byte of binary:

00000001 == 110

If we shift it left (towards the MSB or most significant bit) once, its value doubles.

00000010 == 210

Shifting it left again will double it again:

00000100 == 410

Now let's try this with a larger number, like for example 42.

00101010 == 4210
01010100 == 8410

Shifting right (towards the LSB or least significant bit) will of course divide by two. The only problem becomes when you shift a bit into the bit bucket. You can solve this problem by shifting with carry on some architectures, and then look at the carry bit to determine if you have overflowed the register. If you have done so on a shift right, then your result is the result plus 0.5. If you have done so on a shift left, then the result is the result plus 256 in the case of eight bits, or 2 raised to the number of bits in the register in all cases.

There are other forms of the shift instructions present on some architectures. I will use the x86 instruction set by way of example. x86 includes SAL (shift arithmetic left) and SAR (shift arithmetic right) instructions. SHL (shift left) and SAL do the same thing; for each step, each bit is shifted left one place (from LSB towards MSB) and a 0 is brought into the LSB. However, SAR does something differently; The value of the MSB is preserved, thus preserving the sign of signed integers.

The shift function is related to the rotate operations, which instead of losing the MSB or LSB, move the ordinarily lost bit into its antithesis. Hence a rotate right (ROR) will shift all bits toward the LSB, and move the LSB into the MSB.