From 8a87f3fe33e5724689aa5fefbb74ab03888e2c94 Mon Sep 17 00:00:00 2001 From: i-vishi Date: Thu, 4 Oct 2018 20:08:10 +0530 Subject: [PATCH] Create nextpowOf2.py --- .../next power of 2/python/nextpowOf2.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Bit Manipulation/next power of 2/python/nextpowOf2.py diff --git a/Bit Manipulation/next power of 2/python/nextpowOf2.py b/Bit Manipulation/next power of 2/python/nextpowOf2.py new file mode 100644 index 000000000..b8835d517 --- /dev/null +++ b/Bit Manipulation/next power of 2/python/nextpowOf2.py @@ -0,0 +1,12 @@ +def nextPowOf2(n): + p = 1 + if (n and not(n & (n - 1))): + return n + while (p < n) : + p <<= 1 + return p; + +t = int(input()) +for i in range(t): + n= int(input()) + print("Next Power of 2 " + nextPowOf2(n))