c++ - 无符号窄字符类型数字表示

标签 c++ memory

N3797::3.9.1/1 [basic.fundamental]

For unsigned narrow character types, all possible bit patterns of the value representation represent numbers.

这对我来说有点不清楚。对于窄字符类型,我们有以下范围:

unsigned char := 0 -- 255
signed char : = -128 -- 127

对于 unsgined charsigned char 对象,我们有从这些对象表示中的位集到他们可以代表的整体值(value)。标准说 N3797::3.9.1/1 [basic.fundamental]

These requirements do not hold for other types.

为什么我引用的要求不适用于 signed char 类型?

最佳答案

有符号类型可以使用以下三种表示之一:二进制补码、个人补码或符号大小。最后两个各有一个位模式(零的否定),不代表数字。

补码是more or less现在对于整数类型是通用的;但语言仍然允许其他语言。

关于c++ - 无符号窄字符类型数字表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26249221/

相关文章:

c++ - ZeroMQ 轮询 - 资源暂时不可用

c++ - 从 DirectX 11.2 应用程序打开或创建文件

c++ - 我无法将 cv::Mat 保存到一维数组中

android - Recyclerview数据集更新正确方法

python - Tensorflow CPU内存问题(分配超过系统内存的10%)

c++ - 为什么我们要在这种情况下实现纯虚函数?

c++ - 为什么 C++ 禁止声明无类型的参数?

c++ - C/C++ : do built-in objects such as `int` `double` always stay in the exact place within memory in the duration of the program?

eclipse - 如何找到 Eclipse 允许的最大 MaxPermSize?

c - 静态内存分配和动态内存分配哪个效率更高