用编程语言查询整数范围
所有,
这可能是一个非常愚蠢的问题,但是在编程语言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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它指的是一个8位有符号整数,其中高位用于判断是否为负数:
参见: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:
See: http://en.wikipedia.org/wiki/Two%27s_complement
你是什么意思?
它通常意味着 -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.
通常,值的范围指示它们使用了多少内存,并且它们通常被设计为占用完整字节。
在您的情况下(-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.