diff --git a/algorithms/bit_manipulation/next_highest_pow_2.py b/algorithms/bit_manipulation/next_highest_pow_2.py new file mode 100644 index 00000000..42b1962b --- /dev/null +++ b/algorithms/bit_manipulation/next_highest_pow_2.py @@ -0,0 +1,10 @@ +''' +Finding the next highest power of 2 to the given positve integer +''' + + +def findNextPowerOf2(n): + n = n - 1 + while n & n - 1: + n = n & n - 1 + return n << 1