为什么Int的范围在正面较少??......... [英] Why the Range of Int is less by one at positive side?.........

查看:80
本文介绍了为什么Int的范围在正面较少??.........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

signed int的范围是 - 2 ^ 15到+(2 ^ 15)-1(-32768到32767)为什么

在正范围内少一个? (与消极方面相比..!)

我开始知道它在内部使用2'的赞美来存储

的负数。为什么它使用2'的恭维而不是赞美

来存储负数?

解决方案

Harshan写道:

signed int的范围是 - 2 ^ 15到+(2 ^ 15)-1(-32768到32767)为什么
少于正范围? (与消极面相比......!)


因为我们也需要代表数字零。

我才知道它是


什么是''它'?你指的是实现。


在内部使用2'的赞美来存储
负数。为什么它使用2'的赞美而不是用于存储负数的赞美?




这完全取决于机器/实现。

和ansi C对此没有任何发言权。


-

Karthik。


harshan,


它比一个bcos更少,当

正数被处理时它将零考虑在内。也就是说,如果你想拥有10个最小的非负数,那么它将是0到9而不是1-10。

这就是为什么在正范围内它少一个比预期更多


2005年1月24日星期一15:38:29 +0530,Harshan写道:

signed int的范围是 - 2 ^ 15到+(2 ^ 15)-1(-32768到32767)为什么
在正范围内少一个? (与消极方面相比......!)我知道它在内部使用2'的赞美来存储
负数。为什么它使用2'的赞美而不是用于存储负数的赞美?




C语言允许1'的补码或者符号幅度表示
除了2'的补码外,还有b $ b的有符号整数。你的编译器几乎可以肯定地使用2'的

补码,因为这就是目标使用的处理器。现代处理器倾向于使用2'的补码,因为它b / b
具有一些不错的属性并且可以简化硬件设计(例如你

可以避免单独的有符号和无符号加法指令和

减法)。 1'的补码和符号幅度的一个明显问题是

2个数字的单独表示。


劳伦斯


The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why
the one less at positive Range ? (compared to the negative side..!)
I came to know that it uses 2''s compliment internally for storing the
negative numbers . why it uses 2''s compliment but not the ones compliment
for storing the negative numbers ?

解决方案

Harshan wrote:

The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why
the one less at positive Range ? (compared to the negative side..!)
because we need to represent the number ''zero'' as well.
I came to know that it
What is ''it'' ? Are you referring to the implementation.

uses 2''s compliment internally for storing the
negative numbers . why it uses 2''s compliment but not the ones compliment
for storing the negative numbers ?



This is entirely dependent on the machine / implementation.
And ansi C does not have any say on this.

--
Karthik.


harshan,

it is less by one bcos it takes zero into account when
positive numbers are taken care of. i.e. if u want to have
10 smallest non negative numbers it''ll b frm 0 -9 not 1-10.
thats why at the positive range its one less than as expected


On Mon, 24 Jan 2005 15:38:29 +0530, Harshan wrote:

The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why
the one less at positive Range ? (compared to the negative side..!)
I came to know that it uses 2''s compliment internally for storing the
negative numbers . why it uses 2''s compliment but not the ones compliment
for storing the negative numbers ?



The C language permits a 1''s complement or sign-magnitude representation
of signed integers in addition to 2''s complement. Your compiler uses 2''s
complement almost certainly because that is what the processor it is
targetting uses. Modern processors tend to use 2''s complement because it
has some nice properties and can simplify the hardware design (e.g. you
can avoid separate instructions for signed and unsigned addition and
subtraction). An obvious issue with 1''s complement and sign-magnitude is
2 separate representations for the number zero.

Lawrence


这篇关于为什么Int的范围在正面较少??.........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆