Implementation to check whether a number is a power of 2 or not.
This algorithm uses bit manipulation to check if a number is a power of 2 or not.
AlgorithmLet the input number be n, then the bitwise and between n and n-1 will let us know whether the number is power of 2 or not
For Example, If N= 32 then N-1 is 31, if we perform bitwise and of these two numbers then the result will be zero, which indicates that it is the power of 2 If N=23 then N-1 is 22, if we perform bitwise and of these two numbers then the result will not be zero , which indicates that it is not the power of 2
Definition in file power_of_two.cpp.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4