Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get the nearest power of 2 of your number
public static int nearestPowerOf2(int number) {
--number;
number |= number >>> 1;
number |= number >>> 2;
number |= number >>> 4;
number |= number >>> 8;
number |= number >>> 16;
return ++number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment