/// /// Force an unigned integer to be a power of 2. /// Finds the next highest power of 2, starting at 2 /// /// /// private uint ForcePowerOf2(uint value) { //Force a minimum of 2 uint powerof2 = (value < 2) ? 2 : value; //If the value is not a power of 2, find the next highest. if (((powerof2 & (powerof2 - 1)) != 0)) { //find the next number of powers powerof2 = (uint)((Math.Log(powerof2) / Math.Log(2)) + 1); //raise 2 to the number of powers powerof2 = (uint)Math.Pow(2.0, (Double)powerof2); } //return the new powerof 2 return powerof2; }