Here you can find the source of roundUpToNearestPowerOfTwoIfGreaterThanZero(final int value)
@SuppressWarnings({ "NumericCastThatLosesPrecision", "MagicNumber" }) public static int roundUpToNearestPowerOfTwoIfGreaterThanZero(final int value)
//package com.java2s; // The MIT License (MIT) public class Main { @SuppressWarnings({ "NumericCastThatLosesPrecision", "MagicNumber" }) public static int roundUpToNearestPowerOfTwoIfGreaterThanZero(final int value) { // Inspired by https://graphics.stanford.edu/~seander/bithacks.html long v = value; v--;/*w w w.ja va 2 s.c o m*/ v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return (int) v; } }