I’m sure this isn’t as difficult as I’m making it out to be.
Would like to use something equivalent to Math.Pow(double, double) but outputting an integer. I’m concerned about roundoff errors with the floating points.
The best I can come up with is:
uint myPower = 12;
uint myPowerOfTwo = (uint)Math.Pow(2.0, (double)myPower);
I thought of this:
uint myPowerOfTwo = 1 << myPower; // doesn't work
but I get the error that operator “<<” cannot be used with operands of type int or and uint.
Any suggestions? Thanks as always.
you will have to use a signed integer for the second operand (right hand side) of the shift operator:
Of course you can cast the result to another numeric type such as uint:
From MSDN: