Friday, January 17, 2014

Divide a number by a power of two using bit right shift

In opposite to left shift, when we right shift a number we divide it by a power of two. For example, 4 >> 2 = 0100 >> 2 = 0001 = 1 = 4 / 2^2. Here is the general formula:
a >> b = a / 2^b

Reactions:

0 comments:

Post a Comment