Skip to content

Instantly share code, notes, and snippets.

@kendallm
Created September 13, 2020 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendallm/33eca83a863fcfe8cfbb0b796c21e6a1 to your computer and use it in GitHub Desktop.
Save kendallm/33eca83a863fcfe8cfbb0b796c21e6a1 to your computer and use it in GitHub Desktop.
Calculate the nearest power of 2 that is >= n
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