用编程语言查询整数范围

发布于 2024-09-10 11:29:12 字数 80 浏览 1 评论 0原文

所有,

这可能是一个非常愚蠢的问题,但是在编程语言X中,int范围是-127到+128,这个值是否指的是实际值-127和+128?

All,

This might be a very silly question, but in a Programming lang X where the int range is -127 to +128, does this value refer to the actual value -127 and +128 ?

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

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

发布评论

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

评论(3

皓月长歌 2024-09-17 11:29:12

它指的是一个8位有符号整数,其中高位用于判断是否为负数:

01111111 = 127
00000001 = 1
00000000 = 0
11111111 = -1
11111110 = -2
10000001 = -127
10000000 = -128 or +128 or even -0, depending on the language

参见:http://en.wikipedia.org/wiki/Two%27s_complement

It refers to an 8-bit signed integer, where the high bit is used to determine whether it's negative or not:

01111111 = 127
00000001 = 1
00000000 = 0
11111111 = -1
11111110 = -2
10000001 = -127
10000000 = -128 or +128 or even -0, depending on the language

See: http://en.wikipedia.org/wiki/Two%27s_complement

给我一枪 2024-09-17 11:29:12

你是什​​么意思?

它通常意味着 -127 到 128(含),因此 -127 和 128 本身都是有效值。

What do you mean?

It will typically mean -127 to 128 inclusive, so both -127 and 128 are themselves valid values.

↙温凉少女 2024-09-17 11:29:12

通常,值的范围指示它们使用了多少内存,并且它们通常被设计为占用完整字节。
在您的情况下(-127 到 128),此类型将占用 1 个字节,可以有 256 个不同的值。

因此,您有 127 个负值、128 个正值和 0 值。
127 + 128 + 1 = 256。

因此,值 -127 和 128 包含在该范围内。

Normally, the ranges of the values indicates how much memory they use, and they are normally designed to ocuppy full bytes.
In your case (-127 to 128), this type will occupy 1 byte, which can have 256 different values.

So, you have 127 negative values, 128 positive values, and the 0 value.
127 + 128 + 1 = 256.

So, the values -127 and 128 are included in the range.

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