c++ - C++中有符号到无符号的转换

标签 c++ integer standards c++14 signed

在 C++ 中,将有符号整数值转换为无符号整数值的结果可以是两种不同的大小(例如:short intunsigned long long intlong long intunsigned char) 由标准和平台独立定义(例如,不管符号整数如何表示)?

最佳答案

是的,该值已定义且独立于所使用的表示形式。 [转换积分]/2:

If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type).

显然,目标类型的大小很重要; long longunsigned char 可能产生与 long longunsigned int 不同的值。

关于c++ - C++中有符号到无符号的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33307058/

相关文章:

java - 尝试使用 ArrayList 的方法时出现语法错误?

sql - SQL 有有限状态机定义吗?

c++ - 让模板部分特化与通用实例化共享成员函数

c++ - 通过 atomic::load() 访问 vector 时发生访问冲突

c - 指针增量与C中的索引增量相比如何

查找不在列表中的最小非负整数的算法

c - 简单赋值运算符的原子性

c - C语言是面向对象的吗?

c++ - QtSQL : QSqlRecord doesn't keep the table prefixes

c++ - 在 MFC 对话框应用程序中检查系统时间 24/7