[英]What does ^ operator do?
I thought that ^ did that.我以为 ^ 做到了。 I expected:
我期望:
10^0=1
10^1=10
10^2=100
What I'm getting我得到了什么
10^0=10
10^1=11
10^2=8
the actual code is实际代码是
int value = 10 ^ exp;
replacing exp for 0, 1, and 2 What does the ^ operator do?将 exp 替换为 0、1 和 2 ^ 运算符有什么作用?
Math.Pow(x, y) to get x raised to the power of y. Math.Pow(x, y) 将 x 提高到 y 的幂。 You were doing an XOR.
你正在做一个异或。 C# operators
C# 运营商
You want to do:你想做:
Math.Pow(10, exp);
This actually produces a double
though so you'll need to cast it down if you really want an int
.这实际上会产生一个
double
,所以如果你真的想要一个int
,你需要把它扔掉。
In c#, ^ is the logical XOR operator .在 c# 中,^ 是逻辑 XOR 运算符。
As others have said, you need you use Math.pow(x, y)
to do x^y
in C#.正如其他人所说,您需要使用
Math.pow(x, y)
在 C# 中执行x^y
。 The ^ operator is actually a logical XOR operator on the bits of the two numbers. ^ 运算符实际上是对两个数字的位进行逻辑 XOR 运算符。 More information on the logical XOR can be found here: http://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
可以在此处找到有关逻辑 XOR 的更多信息: http://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
There is no operator for this.没有此操作符。 Use
Math.Pow
.使用
Math.Pow
。
There is a full list of all the C# operators with linked documentation on each one.有所有C# 运算符的完整列表,每个运算符都有链接文档。
Math.Power(10,exp) works like charm...
In C#, the ^ operator is the logical XOR operator.在 C# 中,^ 运算符是逻辑 XOR 运算符。
http://msdn.microsoft.com/en-us/library/6a71f45d.aspx http://msdn.microsoft.com/en-us/library/6a71f45d.aspx
^
is the XOR operator. ^
是 XOR 运算符。
http://en.wikipedia.org/wiki/Xor http://en.wikipedia.org/wiki/Xor
If you want to raise a number to a power, use如果你想提高一个数字的权力,使用
Math.Pow(num, exp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.