码迷,mamicode.com
首页 > 其他好文 > 详细

Bit operator: Left shift and Right shift (Signed or unsigned? )

时间:2014-07-16 12:59:21      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:c++   c   

No matter left shift or right shift, the result‘s sign should always be the same as its left operand.
By default, const numbers in C/C++ is signed.
-Wsign-compare
{
     unsigned int j = 3;
     int k = 5;
     
     if (j == (1 << (j)));  //warning: comparison between signed and unsigned integer expressions.
     if (j == (((unsigned int)1) << (j)));
     if (k == (1 << (k)));
     if (k == (((unsigned int)1) << (k))); //warning: comparison between signed and unsigned integer expressions.
     if (j == (j >> 1));
     if (j == (k >> 1)); //warning: comparison between signed and unsigned integer expressions.
     if (k == (k >> 1));
     if (k == (j >> 1)); //warning: comparison between signed and unsigned integer expressions.
}

Bit operator: Left shift and Right shift (Signed or unsigned? ),布布扣,bubuko.com

Bit operator: Left shift and Right shift (Signed or unsigned? )

标签:c++   c   

原文地址:http://blog.csdn.net/tt33415366/article/details/37872591

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!