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


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

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

C#语言 .net 程序开发

妖狐飛影ゼロ 10 years, 10 months ago


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

redwolf answered 10 years, 10 months ago


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


cccp127 answered 10 years, 10 months ago


似乎还是位运算快。

猫耳基德曼 answered 10 years, 10 months ago


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


苦逼少年-乱码 answered 10 years, 10 months ago


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

迷糊D蜗牛 answered 10 years, 10 months ago


楼上很多正解啊

arorua answered 10 years, 10 months ago


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

轻语的乌鸦 answered 10 years, 10 months 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 10 years, 10 months ago


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

邪恶的怪蜀黍 answered 10 years, 10 months ago


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

zeromax answered 10 years, 10 months ago


低调路过...

Didy answered 10 years, 10 months ago


要再加个Math.Abs取绝对值

世纪末中二传说 answered 10 years, 10 months ago


Math.Sign(a-b)

DERRCJ answered 10 years, 10 months ago

Your Answer