Skip to content

Instantly share code, notes, and snippets.

@majiang
Created September 4, 2012 14:41
Show Gist options
  • Select an option

  • Save majiang/3621793 to your computer and use it in GitHub Desktop.

Select an option

Save majiang/3621793 to your computer and use it in GitHub Desktop.
size_t msb(ulong x)
{
assert (x);
size_t ret = 0;
auto i = 1 << (6 - 1);
while (i)
{
if (x >> i)
{
ret |= i;
x >>= i;
}
i >>= 1;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment