views:

315

answers:

2

hi ,

i have an equation that requires a number to be multiplied by itself for the given number of times , like:

 2 ^ 5

but if i implement the carrot '^' sign it doesnt give the required result ...

am i doing it wrong ?

if so what will be the correct expression for it?

+5  A: 

Use Math.Pow(2, 5)

The carrot sign "^" is used for boolean and bitwise exclusive-OR operations. Your idea that it's used to calculate the power comes from VB/VB.NET.

Dave Van den Eynde
thank you , Dave ;)
jarus
+7  A: 

In C#, ^ is the 'exclusive or' operator. For exponentiation you need to use Math.Pow():

double d = Math.Pow(2, 5);

AakashM
thank's , i'm new to c# so having trouble figuring such things out ..;)
jarus