TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
[Find whether a given number is power of 2] (https://www.geeksforgeeks.org/program-to-find-whether-a-given-number-is-power-of-2/) implementation More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | bit_manipulation |
for assert | |
Functions | |
bool | bit_manipulation::isPowerOfTwo (std ::int64_t n) |
The main function implements check for power of 2. | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
[Find whether a given number is power of 2] (https://www.geeksforgeeks.org/program-to-find-whether-a-given-number-is-power-of-2/) implementation
We are given a positive integer number. We need to check whether the number is power of 2 or not.
A binary number consists of two digits. They are 0 & 1. Digit 1 is known as set bit in computer terms. Worst Case Time Complexity: O(1) Space complexity: O(1)
Definition in file power_of_2.cpp.
int main | ( | void | ) |
|
static |
Self-test implementations.
Definition at line 49 of file power_of_2.cpp.