Skip to content

Instantly share code, notes, and snippets.

@gerdr
Created June 12, 2012 14:17
Show Gist options
  • Select an option

  • Save gerdr/2917817 to your computer and use it in GitHub Desktop.

Select an option

Save gerdr/2917817 to your computer and use it in GitHub Desktop.
next greater power of 2
static inline size_t next_greater_pow2(size_t size)
{
enum { SIZE_BIT = CHAR_BIT * sizeof (size_t) };
for(unsigned exp = 0; (1 << exp) < SIZE_BIT; ++exp)
size |= size >> (1 << exp);
return ++size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment