Bit Shift

Updated: 09/15/2017 by Computer Hope

Bit shiftA bit shift is a bitwise operation in which the order of a series of bits is moved, either to the left or the right, to efficiently perform a mathematical operation. Bit shifts help with optimization in low-level programming because they require fewer calculations for the CPU than conventional math. Bit shifting operations may be declared explicitly by the programmer, or automatically by the compiler if it can identify that such an optimization is possible.

As an example, consider the integer 23, represented with eight bits:

00010111

If we shift all the bits left one place, discard the leftmost bit, and insert a zero on the right, the result is the binary representation of 46:

00101110

This action is effectively the same as multiplying the number by two.

Programming terms