轻松计算和列出二进制组合
我有 5 位,所以有 32 种不同的组合(它们的组合)。
从 开始
00000
到 结束
11111
是否有某种方法可以快速列出所有可能性?我可以用手做,但我担心我可能会错过一个。我猜想某个聪明的小伙子已经编写了一些算法和/或制作了一个网站,可以很容易地做到这一点。至少我希望如此。
多谢。
I have 5 bits and so 32 different combinations (of them).
Starting from
00000
and ending with
11111
Is there some way of quickly listing all possibilities? I could do it by hand, but I worry that I might miss one. I'm guessing some clever chap has written some algorithm and/or made a website, that can do this very easily. At least I hope so.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这会将它们全部放在 Linux 的命令行上。
回显{0..1}{0..1}{0..1}{0..1}{0..1}
This will put them all on the command line on Linux.
echo {0..1}{0..1}{0..1}{0..1}{0..1}
在红宝石中:
In Ruby:
将 0 到 31 之间的整数写入一列,然后将每个整数的二进制等价并排写入第二列。
这样您将增加不错过组合的机会。
Write a column with integer from 0 to 31, then write a second column with the binary equivalent of each integer side-by-side.
That way you will increase your chance not to miss a combination.
只需从 0 数到 31 并以二进制形式输出该数字。
像这样的事情应该做:
输出:
Just count from 0 to 31 and output the digit in it's binary form.
Something like this should do:
Output:
for (int i = 0; i <31; i++)
计算<< ((i & 16) >> 4) << ((i & 8) >> 3) << ((i & 4) >> 2)
<< ((i & 2) >> 1) << (i&1)<<结束;
for (int i = 0; i <31; i++)
cout << ((i & 16) >> 4) << ((i & 8) >> 3) << ((i & 4) >> 2)
<< ((i & 2) >> 1) << (i & 1) << endl;
Unix:
Unix: