Detect if a number is power of 4 using bitwise operators

bitwise-operation
bitwise-algorithm
power-of-2
power-of-4

(Team) #1

Reading time: 15 minutes | Coding time: 2 minutes

Bitwise operators are one of the most under-rated operators in C/C++, despite being quite fast as most of the processors today have direct support for bit level operators.


This is a companion discussion topic for the original entry at http://iq.opengenus.org/using-bitwise-operators-to-detect-if-number-is-power-of-four-4/