【问题标题】:What is signed char? [duplicate]什么是签名字符? [复制]
【发布时间】:2014-02-27 23:32:29
【问题描述】:

我了解signedunsigned int 的含义。但是signed char 对我来说没有任何意义。 还有为什么signed and unsigned int 占用相同的空间。 Signed int 应该占用更多空间,因为它可以包含负数和正数。 提前致谢。

【问题讨论】:

  • 关于整数问题,都是关于数字的范围。检查有符号和无符号整数的范围。
  • char不是字母,是1字节整数,默认带符号。
  • signed char 代表 -128 ~ 127。unsigned char 代表 0 ~ 255。signed int 代表 -2,147,483,648 ~ 2,147,483,647 和 unsigned int 代表 0 ~ 4,294,967,2 ) 系统(在 Microsoft Visual Studio 20xx 中)。它们是相同大小的数字,对吧?

标签: c


【解决方案1】:

符号占用一位。

因此,无符号字符的值可以是 0 到 255,而有符号字符的值可以是 -128 到 127。

所以有符号和无符号的位数相同,可以有相同数量的值,但有符号值可以表示负值,但不能表示正值。

【讨论】:

  • 实际范围在CHAR_BIT 大于 8 和/或负数未在二进制补码中表示的地方有所不同。
猜你喜欢
  • 1970-01-01
  • 2016-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-01
  • 2019-05-24
  • 1970-01-01
相关资源
最近更新 更多