How do I calculate power-of in C#?

后端 未结 8 1564
别跟我提以往
别跟我提以往 2021-01-01 08:08

I\'m not that great with maths and C# doesn\'t seem to provide a power-of function so I was wondering if anyone knows how I would run a calculation like this:



        
8条回答
  •  春和景丽
    2021-01-01 09:13

    For powers of 2:

    var twoToThePowerOf = 1 << yourExponent;
    // eg: 1 << 12 == 4096
    

提交回复
热议问题