Bit shift

Updated: 12/31/2022 by Computer Hope
Bit shift

A bit shift is a bitwise operation where the order of several bits is moved, either to the left or right, to efficiently perform a mathematical operation. Bit shifts help with optimization in low-level programming because they require fewer calculations for the CPU (Central Processing Unit) 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.

For 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