From 3863edfdf73863b260050036b78a420e30bc9850 Mon Sep 17 00:00:00 2001 From: Harshal Pamecha Date: Tue, 14 Dec 2021 16:10:50 +0530 Subject: [PATCH] added checkPowerof2 Function in Bit manipulation --- Bit manipulation/checking_power_of_2.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Bit manipulation/checking_power_of_2.cpp diff --git a/Bit manipulation/checking_power_of_2.cpp b/Bit manipulation/checking_power_of_2.cpp new file mode 100644 index 0000000..741e65e --- /dev/null +++ b/Bit manipulation/checking_power_of_2.cpp @@ -0,0 +1,15 @@ +#include +#include + +using namespace std; + +/* + Program to find whether a given number is power of 2. +*/ + +bool checkPowerOf2(int n) +{ + if((n & (n-1)) == 0) + return true; + return false; +} \ No newline at end of file