移位运算符用C [英] Shift operator in C

查看:371
本文介绍了移位运算符用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

根据 K&安培; R第二版(圣经) 结果是实现定义的符号值的右移。

According to K&R Second edition (the bible) the results are implementation-defined for right-shifts of signed values.

维基百科说,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 they do an arithmetic shift.

这篇关于移位运算符用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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