首页 > 其他 > 详细

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

时间:2014-07-16 12:59:46      阅读:343      评论:0      收藏:0      [点我收藏+]
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? )

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!