本文介绍了左移/右移算子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有什么方法可以捕捉因右移而发生的损失位

运营商?


例如

int a = 5;

a = a> 1; // // a现在为2,最低有效位丢失//

//


我想要这个问题的解决方案:

"如何仅使用<<<<"来查找数字是偶数还是奇数或/和>>"

运营商?"

Hi,
Is there any way to catch the losing bit occurring due to Right Shift
Operator ?

e.g
int a = 5 ;
a = a >1 ; // // a is now 2 and the least significant bit is lost //
//

I want this solution for the question:
"How to find if the number is even or odd using only "<<" or/and ">>"
operators ?"

推荐答案



int a = 5;

int lost_bit = a& 1;

a = a> 1;

/ *现在lost_bit保留丢失的位* /

int a = 5;
int lost_bit = a & 1;
a = a >1;
/* now lost_bit holds the lost bit */



我们不会为你做功课。继续思考。


-Arthur

We won''t do your homework for you. Keep thinking.

-Arthur




也许,我不清楚我的问题。

我的意思是我们不应该使用任何其他按位运算符其他

比<<"或>>。

"&"不允许使用。

Perhaps, i was not clear about my question.
I meant we are not supposed to use any other bitwise operators other
than "<<" or ">>".
"&" operator is not allowed.



这篇关于左移/右移算子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:43