左移/右移算子 [英] Left Shift / Right Shift Operators
问题描述
有没有什么方法可以捕捉因右移而发生的损失位
运营商?
例如
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 ?"
推荐答案
On Thu,2006年11月29日,Santosh Nayak写道:
On Thu, 29 Nov 2006, Santosh Nayak wrote:
>
有没有办法赶上由于右移而失去比特
运营商?
>
Is there any way to catch the losing bit occurring due to Right Shift
Operator ?
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 */
我想要这个问题的解决方案:
"如何仅使用<<<<""或/和>>
运营商?
I want this solution for the question:
"How to find if the number is even or odd using only "<<" or/and ">>"
operators ?"
我们不会为你做功课。继续思考。
-Arthur
We won''t do your homework for you. Keep thinking.
-Arthur
11月30日上午11:54,Arthur J. O'Dwyer ; < ajonos ... @ andrew.cmu.edu>
写道:
On Nov 30, 11:54 am, "Arthur J. O''Dwyer" <ajonos...@andrew.cmu.edu>
wrote:
int a = 5;
int lost_bit = a& 1;
int a = 5;
int lost_bit = a & 1;
也许,我不清楚我的问题。
我的意思是我们不应该使用任何其他按位运算符其他
比<<"或>>。
"&"不允许使用。
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.
#include< stdio.h>
#include< stdlib.h>
int main(int argc,char ** argv){
int i = atoi(argv [1]);
if(i& 1)
printf(" odd \\\
");
else {
if(i == 0)
printf(invalid\\\
);
else
printf(" even\\\
);
}
返回0;
}
适用于你//从命令行传递号码
问候,
Onkar
Santosh Nayak写道:
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char **argv){
int i=atoi(argv[1]);
if(i&1)
printf("odd\n");
else{
if(i==0)
printf("invalid\n");
else
printf("even\n");
}
return 0;
}
will work for u // pass number from command line
regards,
Onkar
Santosh Nayak wrote:
是否有任何方法可以捕捉因右移而发生的损失位
运营商?
例如
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 ?"
这篇关于左移/右移算子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!