有符号整数和无符号整数有什么区别。任何人都可以帮助我吗? [英] What is the difference between signed and unsigned integer.Can any one help me?

查看:93
本文介绍了有符号整数和无符号整数有什么区别。任何人都可以帮助我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有符号和无符号整数有什么区别。任何人都可以帮帮我吗?

What is the difference between signed and unsigned integer.Can any one help me?

推荐答案

简单:一个可以包含负值,另一个则不能。



为了扩展一点,有符号值使用一位(通常是顶部或最高位)来指示数字是正数还是负数,以及无符号数整数使用数字的所有可用位 - 所以可以保持的不同值的数量是相同的,但值的范围是不同的。

假设我们使用了4位处理器(以使数字更容易)

未签名:

Simple: one can contain negative values, the other can't.

To expand a little, a signed value uses one bit (usually the top, or most significant bit) to indicate if the number is positive or negative, and an unsigned integer uses all available bits for the number - so the number of different values that can be held is the same, but the range of values is different.
Assume we used a 4 bit processor (to make the numbers easier)
Unsigned:
Bits   Value (decimal)
0000     0
0001     1
0010     2
0011     3
0100     4
0101     5
0110     6
0111     7
1000     8
1001     9
1010    10
1011    11
1100    12
1101    13
1110    14
1111    15

签名:

Signed:

Bits   Value (decimal)
0000     0
0001     1
0010     2
0011     3
0100     4
0101     5
0110     6
0111     7
1000    -8
1001    -7
1010    -6
1011    -5
1100    -4
1101    -3
1110    -2
1111    -1

-8有时被视为减零,但你可以忽略它!

-8 in this scheme is sometimes treated as "minus zero" but you can probably ignore that!


参见在其中 [ ^ ]作为一般性解释。
See here[^] for a general explanation.


这篇关于有符号整数和无符号整数有什么区别。任何人都可以帮助我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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