

Now since we have got enough idea about the shift operators let's use them to divide a number with another number. Similarly when a number is pushed to the left by n bits means the number is multiplied by 2 power n. As a result, when we push a number towards the left by 1 bit the whole number gets multiplied by 2 power 1. Taking a look at the table we can see that the positional weight of each of the following bits is twice the previous bit i.e. We know that the binary number system is based on powers of 2. The left shift operator is used to shift the given number to the left by a certain number of bits as shown below.īut what happens when we left shift it? let's take a closer look. Recap of required bitwise operationsīefore we jump into the problem let's make a quick recall about the bitwise shift operators because that's what we are going to use to solve this problem. So, we need to write a function to do this but by using the bitwise operators. Let's see it with an example, consider 96 and 7 just the decimal quotient, but we should be using bitwise operators, not the usual operators like * / % to divide the number. So the task here is to divide a given number with another number and return the floor value i.e. We will explore the algorithm of bitwise algorithm now.
Xlist divide operator how to#
In this article, we will see how to divide a number using the bitwise operator > rather than using the regular division operator / or the multiplication operator * or the modulo operator %.
