【发布时间】:2025-12-28 18:35:06
【问题描述】:
我想确定一个数字是否在
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
...
我试过这个:
public static void Main(string[] args)
{
int result = 1;
for (int i = 0; i < 15; i++)
{
//Console.WriteLine(result);
Console.WriteLine(result % 2);
result *= 2;
}
}
As you can see 它返回
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...
我应该如何有效地将上述打印为0,包括1?
【问题讨论】:
-
是的,我可以看到。有什么问题吗?
-
我知道代码按预期工作。我的问题是编写什么代码来打印 我 期望的内容。
-
@CodeInChaos,我投票决定关闭它。感谢您的参考。
-
对于一些琐碎的问题,经常有答案:www-graphics.stanford.edu/~seander/…