为什么空头只能容纳 65,536 个可能的值?

发布于 2024-12-12 22:20:11 字数 191 浏览 3 评论 0原文

我知道使用 Short 可以有 65,536 个可能的整数,但为什么不能有 255,256 个可能的值(0 到 255,255 个无符号)?我发现你可以这样做:

2 byte integer

有人已经想到了这一点吗?为什么没有使用它?

I understand that with a short you can have 65,536 possible ints, but why can't you have 255,256 possible values (0 to 255,255 unsigned)? I see that you could do it like this:

2 byte integer

Has someone already thought of this? Why isn't it used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

厌味 2024-12-19 22:20:11

那是行不通的。
您将如何存储254,300

That wouldn't work.
How would you store 254,300?

冬天旳寂寞 2024-12-19 22:20:11

因为它是两个字节,256 * 256 = 65536。

Because it is two bytes and 256 * 256 = 65536.

凑诗 2024-12-19 22:20:11

第一个字节有 256 个选项,第二个字节有 256 个选项。总计:256 乘以 256,即 65,536。

如果您建议您可以用这种方式写出 0 到 255,255 范围内的任何小数,请记住您不能写出 123,456 之类的数字,因为 456 不在 0 到 255 范围内。

(如果您完成了整个操作)以二进制形式,那么你就会得到正确的答案。)

There are 256 options for the first byte, and 256 for the second. Altogether: 256 times 256, or 65,536.

If you suggest you could write any decimal in the range 0 to 255,255 this way, remember you cannot write numbers such as 123,456 because 456 is not in the range 0 to 255.

(If you did the whole thing in binary, then it would work. And you'd get the correct answer.)

可是我不能没有你 2024-12-19 22:20:11

您将无法在您的方案中表示数字 500、1,783 或 63,443 以及许多其他数字。仍然会有 65,536 = 2^16 独特的位模式,因此您可以在您的方案中表示数字......因此它会清楚地引入间隙,并且它会引入的三个间隙包含上面提到的三个数字。

You wouldn't be able to represent the numbers 500, 1,783, or 63,443 in your scheme, among many, many others. There would still be 65,536 = 2^16 unique bit patterns, hence numbers, you could represent in your scheme... So it would clearly introduce gaps, and three of the gaps it would introduce contain the three numbers mentioned above.

庆幸我还是我 2024-12-19 22:20:11

因为它不是以1000为基础的! 256 * 256 = 65,536

Since it is not in the basis of 1000! 256 * 256 = 65,536

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文