Signed versus Unsigned Integers

2019-01-02 19:17发布

Am I correct to say the difference between a signed and unsigned integer is:

  1. Unsigned can hold a larger positive value, and no negative value.
  2. Unsigned uses the leading bit as a part of the value, while the signed version uses the left-most-bit to identify if the number is positive or negative.
  3. signed integers can hold both positive and negative numbers.

Any other differences?

15条回答
裙下三千臣
2楼-- · 2019-01-02 19:49

(in answer to the second question) By only using a sign bit (and not 2's complement), you can end up with -0. Not very pretty.

查看更多
余欢
3楼-- · 2019-01-02 19:50

Unsigned can hold a larger positive value, and no negative value.

Yes.

Unsigned uses the leading bit as a part of the value, while the signed version uses the left-most-bit to identify if the number is positive or negative.

There are different ways of representing signed integers. The easiest to visualise is to use the leftmost bit as a flag (sign and magnitude), but more common is two's complement. Both are in use in most modern microprocessors — floating point uses sign and magnitude, while integer arithmetic uses two's complement.

signed integers can hold both positive and negative numbers.

Yes

查看更多
还给你的自由
4楼-- · 2019-01-02 19:51

According to what we learned in class, signed integers can represent both positive and negative numbers, while unsigned integers are only non-negative.

For example, looking at an 8-bit number:

unsigned values 0 to 255

signed values range from -128 to 127

查看更多
登录 后发表回答