Introduction to Bit Shifting

We learned the most common Bitwise operations so far. Now, we are about to learn shifting, which is a common operation we use when we divide/multiply a number by 2.

We'll cover the following

What is shifting?

A bit shift is a Bitwise operation where the order of a series of bits is moved, either to the left or right, to efficiently perform a mathematical operation.

A bit shift moves each digit in a number’s binary representation left or right. The bit-shifting operators do precisely what their name implies: they shift bits. Here is a brief introduction to the different shift operators.

Types

There are three main types of shifts:

  1. Left shift: << is the left shift operator and meets both logical and arithmetic shifts’ needs.
  2. Arithmetic/signed right shift: >> is the arithmetic (or signed) right shift operator.
  3. Logical/unsigned right shift: >>> is the logical (or unsigned) right shift operator.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.