首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >uint8_t与二进制OR

uint8_t与二进制OR
EN

Stack Overflow用户
提问于 2017-12-06 17:18:30
回答 1查看 295关注 0票数 0

有人知道为什么uint8_t&uint8_t会产生int吗?

代码语言:javascript
复制
#include <iostream>
#include <type_traits>
#include <cstdint>
#include <typeinfo>

using namespace std;

int main() {
    {
        uint8_t a {}, b{};
        auto c = a & b ;
        cout << is_unsigned<decltype(a)>::value << " "<< is_unsigned<decltype(b)>::value 
        << " "<< is_unsigned<decltype(c)>::value << " "<< is_unsigned<decltype( a & b)>::value << " ";
        cout << "\t " << typeid(a).name() << " " << typeid(c).name() << endl;
    }
    cout << endl;
    {
        uint32_t a {}, b{};
        auto c = a & b ;
        cout << is_unsigned<decltype(a)>::value << " "<< is_unsigned<decltype(b)>::value 
        << " "<< is_unsigned<decltype(c)>::value << " "<< is_unsigned<decltype( a & b)>::value << " ";
        cout << "\t " << typeid(a).name() << " " << typeid(c).name() << endl;

    }
    cout << endl;
    {
        size_t a {}, b{};
        auto c = a & b ;
        cout << is_unsigned<decltype(a)>::value << " "<< is_unsigned<decltype(b)>::value 
        << " "<< is_unsigned<decltype(c)>::value << " "<< is_unsigned<decltype( a & b)>::value << " ";
        cout << "\t " << typeid(a).name() << " " << typeid(c).name() << endl;

    }
}

住在这里:胡桃

产出如下:

代码语言:javascript
复制
1 1 0 0      h i

1 1 1 1      j j

1 1 1 1      m m

我没有找到任何线索,只是:

运算符的结果&是操作数的位和值(在通常的算术转换之后)。

所以,我不知道它是标准的还是实现的依赖者。

(谢谢你的帮助:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-06 17:24:37

请参见推广所有算术操作都会将小于int的整数类型推广到int或无符号int。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47679982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档