移位运算符(<<,>>)在 C 中是算术还是逻辑? [英] Are the shift operators (<<, >>) arithmetic or logical in C?

查看:24
本文介绍了移位运算符(<<,>>)在 C 中是算术还是逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C 中,移位运算符(<<>>)是算术还是逻辑?

In C, are the shift operators (<<, >>) arithmetic or logical?

推荐答案

根据K&R 第 2 版 对于有符号值的右移,结果取决于实现.

According to K&R 2nd edition the results are implementation-dependent for right shifts of signed values.

Wikipedia 说 C/C++通常"对有符号值实现算术移位.

Wikipedia says that C/C++ 'usually' implements an arithmetic shift on signed values.

基本上你需要测试你的编译器或者不依赖它.我对当前 MS C++ 编译器的 VS2008 帮助说他们的编译器进行了算术移位.

Basically you need to either test your compiler or not rely on it. My VS2008 help for the current MS C++ compiler says that their compiler does an arithmetic shift.

这篇关于移位运算符(&lt;&lt;,&gt;&gt;)在 C 中是算术还是逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆