c++右移分两种

老哥们,很奇怪,我这样8个f右移了16位,还是这样
按理是应该0000FFFF

 

 

 

---------------

int temp_i = 0x0FFFFFFF >> 16;
cout << "temp_i==" << temp_i << endl;
printf("temp_i == %08X\n", temp_i);

输出0000FFFF

---------------

const unsigned int ALL_ONE = 0xFFFFFFFF;

int temp_i = ALL_ONE >> 16;
cout << "temp_i==" << temp_i << endl;
printf("temp_i == %08X\n", temp_i);

输出0000FFFF

---------------

在vs2015里。写0xFFFFFFFF会被认为是unsigned int,

写0x0FFFFFFF会被认为是signed int。

---------------

解答:

c++右移分两种

对于有符号数,是补充的符号位

所以全部补1

 

posted @ 2022-02-18 11:06  暴风城  阅读(101)  评论(0编辑  收藏  举报