From ccc3417c66f76c28057ca3daab89f0dc760ab5ae Mon Sep 17 00:00:00 2001 From: Ravishankar Joshi <21024229+ravibitsgoa@users.noreply.github.com> Date: Fri, 23 Oct 2020 20:32:42 +0530 Subject: [PATCH] Removed Power of 2 and xor swap. --- bit_manipulation/power_of_2.cpp | 27 --------------------------- bit_manipulation/xor_swap.cpp | 19 ------------------- 2 files changed, 46 deletions(-) delete mode 100644 bit_manipulation/power_of_2.cpp delete mode 100644 bit_manipulation/xor_swap.cpp diff --git a/bit_manipulation/power_of_2.cpp b/bit_manipulation/power_of_2.cpp deleted file mode 100644 index a37812d37..000000000 --- a/bit_manipulation/power_of_2.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** - * @file - * @brief Finding if a number is a power of 2. - * - * @details - * To find if a number is a power of 2, we can check if bitwise AND of number - * and number - 1 is zero or not. Only for the numbers which are a power of 2, - * bitwise AND(x, x-1) is zero. - * - * @author [Ravishankar Joshi](https://github.com/ravibitsgoa) - */ - -#include -#include -using std::cout; -using std::endl; -using std::vector; - -bool ispower2(int x) { return x > 0 && (x & (x - 1)) == 0; } - -int main() { - vector arr{1, 2, 3, 4, 8, 10}; - for (int x : arr) { - cout << x << " is " << (ispower2(x) ? "" : "not ") << "a power of 2." - << endl; - } -} \ No newline at end of file diff --git a/bit_manipulation/xor_swap.cpp b/bit_manipulation/xor_swap.cpp deleted file mode 100644 index 4134d18df..000000000 --- a/bit_manipulation/xor_swap.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @file - * @brief Swapping two integers using xor. - * - * @author [Ravishankar Joshi](https://github.com/ravibitsgoa) - */ - -#include -using std::cout; -using std::endl; - -int main() { - int a = 1, b = 2; - cout << "a = " << a << ", b = " << b << endl; - a ^= b; - b ^= a; - a ^= b; - cout << "a = " << a << ", b = " << b << endl; -} \ No newline at end of file