请教,怎么比较两个数,相同为0,不同为1 或者 相同为1,不同为0


请问,如何比较两个数,相同为0,不同为1 或者 相同为1,不同为0?
比如 int a,b,c;

如果a==b,c就是0,如果a!=b,c就是1

C#语言 .net 程序开发

妖狐飛影ゼロ 12 years ago


果然是变态题目。。。
好好的if else 或者 :不用。。。

redwolf answered 12 years ago


<fieldset> <legend> 探讨 </legend>
似乎还是位运算快。
</fieldset>


cccp127 answered 12 years ago


似乎还是位运算快。

猫耳基德曼 answered 12 years ago


<fieldset> <legend> 探讨 </legend>
请问楼主,这样的意义何在???
看不懂。。。。
</fieldset>


苦逼少年-乱码 answered 12 years ago


请问楼主,这样的意义何在???
看不懂。。。。

迷糊D蜗牛 answered 12 years ago


楼上很多正解啊

arorua answered 12 years ago


问题不错,
做个记录...

轻语的乌鸦 answered 12 years ago


为何不用位运算

  C# code

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; namespace CSharpTest { class Program { static void Main(string[] args) { int a = 3, b = 4; Console.WriteLine((a^b) > 1 1:0); } } }

天天看飞机 answered 12 years ago


或者这样: c = Convert.ToInt32(!((a ^ b) == 0));
保险一些

邪恶的怪蜀黍 answered 12 years ago


c = Convert.ToInt32( (a ^ b) > 0);

zeromax answered 12 years ago


低调路过...

Didy answered 12 years ago


要再加个Math.Abs取绝对值

世纪末中二传说 answered 12 years ago


Math.Sign(a-b)

DERRCJ answered 12 years ago

Your Answer