Skip to main content TerryFunggg Blog

Why Bitshift(1)

One “old school” reason to use bitshift, is division and multiplication.

As you know, doing division or multiplication in computer it taskes a lot step then add/minus.(Now mordern PC will not feel this. But it still an issue in some extreme cases.)

Bitshift help PC do super faster on division and multiplication.

When we shift right 1 bit, it performs a division by 2 in decimal:

code snippet start

Before: 00001100  // 12 in decimal
----right sihift 1bit-------
After:  00000110  // 6 in decimal

code snippet end

When we shift “left” 1 bit, it performs a multiplication by 2 in decimal:

code snippet start

Before: 00001100  // 12 in decimal
----left sihift 1bit-------
After:  00011000  // 24 in decimal

code snippet end