小编use*_*809的帖子

为什么unsigned char << unsigned char的结果不是unsigned char

我从左移获得结果,我无法找到解释.

unsigned char value = 0xff; // 1111 1111
unsigned char  = 0x01; // 0000 0001

std::cout << "SIZEOF value " << sizeof(value) << "\n"; // prints 1 as expected
std::cout << "SIZEOF shift " << sizeof(shift) << "\n"; // prints 1 as expected

std::cout << "result " << (value << shift) << "\n"; // prints 510 ???

std::cout << "SIZEOF result " <<  sizeof(value << shift) << "\n"; // prints 4 ???
Run Code Online (Sandbox Code Playgroud)

我期待结果,1111 1110但我得到int(?)的价值1 …

c++ bit-manipulation

7
推荐指数
1
解决办法
1248
查看次数

标签 统计

bit-manipulation ×1

c++ ×1