Detect if a number is power of 2 using bitwise operators

bitwise-operation
bitwise-algorithm
power-of-2
and-operation

(Team) #1

Reading time: 15 minutes | Coding time: 1 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/detect-if-a-number-is-power-of-2-using-bitwise-operators/