Browse - Programming Tips - Can I use bitwise operators to speed up multiply and divides by 2?

Date: 2015aug14
Language: C/C++

Q.  Can I use bitwise operators to speed up multiply and divides by 2?

A.

Dividing by 2 can be replaced by a right shift

i / 2 -> i>>1 i / 4 -> i>>2
Multiplying by 2 can be replaced by a left shift
i * 2 -> i<<1 i * 4 -> i<<2
Checking for odd or even
i % 2 -> i & 0x01