using System;
class MainClass
{
static void Main()
{
ushort num; num = 12; if ((num & 1) == 1) //( 整数 & 奇数 显示整数 )等于1 是假
Console.WriteLine("这将无法显示。"); num = 11; if ((num & 1) == 1) //( 奇数 & 奇数 显示奇数 )等于1 是真
Console.WriteLine(num + " 是奇数.");
}
}
class MainClass
{
static void Main()
{
ushort num; num = 12; if ((num & 1) == 1) //( 整数 & 奇数 显示整数 )等于1 是假
Console.WriteLine("这将无法显示。"); num = 11; if ((num & 1) == 1) //( 奇数 & 奇数 显示奇数 )等于1 是真
Console.WriteLine(num + " 是奇数.");
}
}
12的二进制为 1100
& 0001
结果为二进制的
0000所以为 011的二进制为 1011
& 0001
结果为二进制的
0001 所以为1
if ((num & 1) == 1) //( 整数 & 奇数 显示整数 )等于1 是假
{}
else
Console.WriteLine("这将无法显示。");
if ((num & 1) != 1) //( 整数 & 奇数 显示整数 )等于1 是假
Console.WriteLine("这将无法显示。");
& 二进制的与操作 只有在1 1 时为1 其它都是零
基础课没上好?
你自己不是解释的很好吗
假了还怎么显示输出呢