32位类型(int、long等)右移(>>)32位

来源:互联网 发布:淘宝店铺招牌是哪个 编辑:程序博客网 时间:2024/06/13 11:44

思考

int i = 512;
cout << (i >> 32); // 512 (为什么是512,不是0么)

右移操作

在C99中,对右移有这样的规定:
If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.

也就是说,对于右移大于或等于位宽的操作,或者右移负数的操作,其结果将依赖于编译器的处理和硬件指令的处理,并不唯一。

0 0
原创粉丝点击