Created
September 13, 2020 20:59
-
-
Save kendallm/33eca83a863fcfe8cfbb0b796c21e6a1 to your computer and use it in GitHub Desktop.
Calculate the nearest power of 2 that is >= n
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
def nearest_power_of_2(n): | |
return 2 ** ceil(log2(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment